Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Cypher 5.1

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}

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.