Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
13
Task/Caesar-cipher/Groovy/caesar-cipher-1.groovy
Normal file
13
Task/Caesar-cipher/Groovy/caesar-cipher-1.groovy
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
def caesarEncode(cipherKey, text) {
|
||||
def builder = new StringBuilder()
|
||||
text.each { character ->
|
||||
int ch = character[0] as char
|
||||
switch(ch) {
|
||||
case 'a'..'z': ch = ((ch - 97 + cipherKey) % 26 + 97); break
|
||||
case 'A'..'Z': ch = ((ch - 65 + cipherKey) % 26 + 65); break
|
||||
}
|
||||
builder << (ch as char)
|
||||
}
|
||||
builder as String
|
||||
}
|
||||
def caesarDecode(cipherKey, text) { caesarEncode(26 - cipherKey, text) }
|
||||
7
Task/Caesar-cipher/Groovy/caesar-cipher-2.groovy
Normal file
7
Task/Caesar-cipher/Groovy/caesar-cipher-2.groovy
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
def caesarEncode(cipherKey, text) {
|
||||
text.chars.collect { c ->
|
||||
int off = c.isUpperCase() ? 'A' : 'a'
|
||||
c.isLetter() ? (((c as int) - off + cipherKey) % 26 + off) as char : c
|
||||
}.join()
|
||||
}
|
||||
def caesarDecode(cipherKey, text) { caesarEncode(26 - cipherKey, text) }
|
||||
4
Task/Caesar-cipher/Groovy/caesar-cipher-3.groovy
Normal file
4
Task/Caesar-cipher/Groovy/caesar-cipher-3.groovy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def caesarEncode(k, text) {
|
||||
(text as int[]).collect { it==' ' ? ' ' : (((it & 0x1f) + k - 1) % 26 + 1 | it & 0xe0) as char }.join()
|
||||
}
|
||||
def caesarDecode(k, text) { caesarEncode(26 - k, text) }
|
||||
4
Task/Caesar-cipher/Groovy/caesar-cipher-4.groovy
Normal file
4
Task/Caesar-cipher/Groovy/caesar-cipher-4.groovy
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
def caesarEncode(k, text) {
|
||||
text.tr('a-zA-Z', ((('a'..'z')*2)[k..(k+25)] + (('A'..'Z')*2)[k..(k+25)]).join())
|
||||
}
|
||||
def caesarDecode(cipherKey, text) { caesarEncode(26 - cipherKey, text) }
|
||||
5
Task/Caesar-cipher/Groovy/caesar-cipher-5.groovy
Normal file
5
Task/Caesar-cipher/Groovy/caesar-cipher-5.groovy
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
def caesarEncode(k, text) {
|
||||
def c = { (it*2)[k..(k+25)].join() }
|
||||
text.tr('a-zA-Z', c('a'..'z') + c('A'..'Z'))
|
||||
}
|
||||
def caesarDecode(cipherKey, text) { caesarEncode(26 - cipherKey, text) }
|
||||
10
Task/Caesar-cipher/Groovy/caesar-cipher-6.groovy
Normal file
10
Task/Caesar-cipher/Groovy/caesar-cipher-6.groovy
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
def plainText = "The Quick Brown Fox jumped over the lazy dog"
|
||||
def cipherKey = 12
|
||||
def cipherText = caesarEncode(cipherKey, plainText)
|
||||
def decodedText = caesarDecode(cipherKey, cipherText)
|
||||
|
||||
println "plainText: $plainText"
|
||||
println "cypherText($cipherKey): $cipherText"
|
||||
println "decodedText($cipherKey): $decodedText"
|
||||
|
||||
assert plainText == decodedText
|
||||
Loading…
Add table
Add a link
Reference in a new issue