def scrambler = [ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'UWYGADFPVZBECKMTHXSLRINQOJ' ] def reflector = [ 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'YRUHQSLDPXNGOKMIEBFZCWVJAT' ] // Verschlüsselter Text def ciphertext = 'ZYDNI' // Aktuelle Rotation des Scramblers def rotation = 0 // Unverschlüsselter Text def plaintext = ciphertext.collect { x -> // Scrambler drehen rotation++ // Start-Position def i = toInt(x) // Durch den Scrambler (Hinweg) i = mod26(i + rotation) def s = scrambler[0][i] i = scrambler[1].indexOf(s) - rotation // Durch den Reflector i = mod26(i) def r = reflector[1][i] i = reflector[0].indexOf(r) // Durch den Scrambler (Rückweg) i = mod26(i + rotation) s = scrambler[1][i] i = scrambler[0].indexOf(s) - rotation return toChar(i) }.join() // Plaintext ausgeben println plaintext // Hilfsfunktionen def mod26(x) { ( (x % 26) + 26 ) % 26 } int toInt(x) {x.toCharacter() - 65} char toChar(x) {(mod26(x) + 65) as char}
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more