Didactic Feedback Cipher 2

Discussion of challenges you have already solved
Post Reply
User avatar
Grusewolf
Posts: 16
Joined: Sun May 29, 2011 7:58 pm
Location: Munich

Didactic Feedback Cipher 2

Post by Grusewolf »

I solved it in groovy.
For the key k, it seems, that there is no way to calculate it and so the 1st plaintext byte (plain[0]) can just be guessed. Of course in this case, the first plain byte was not needed and guessing it after resolving was easy.

Code: Select all

def cipherString = '310a7718781f73...'
def cipher = string2List(cipherString)
(0..255).each {key->
    printAscii(decrypt(cipher, key))
}

def decrypt(cipher, key) {
    def plain = new byte[cipher.size()]

    for(i in (cipher.size()-1..<0)) {
        byte roundKey = (cipher[i-1] + key) % 0x100
        plain[i] = cipher[i] ^ roundKey
    }
    plain[0] = 32
    return plain
}

def string2List(String hexString) {
    def list = []
    for (index = 0; index < hexString.size() - 1; index += 2) {
        list += Integer.parseInt(hexString[index..index + 1], 16)
    }
    return list
}

def printAscii(list){
    println list.collect{(char) it}.join()
}
Post Reply