4 ms·
It feels like the key leaks a lot into the encoded sequence. Just try encoding a sequence of 0x00 0x00 0x00 0x00... #include <stdio.h> int mai
by dchichkov 13y ago
It feels like the key leaks a lot into the encoded sequence. Just try encoding a sequence of 0x00 0x00 0x00 0x00...
#include <stdio.h>
int main() {
char key[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
int key_size = sizeof(key) / sizeof(key[0]);
int pos_a = key[0];
int pos_b = key[1];
int pos_c = key[2];
char encrypted[100], decrypted[100];
for(int i = 0; i< 100; i++) encrypted[i] = 0;
for(int i = 0; i < 100; i++)
{
int old_a = pos_a;
pos_a = key[pos_b] % key_size;
pos_b = (pos_a + 1 + key[pos_c] % (key_size - 1)) % key_size;
pos_c = (pos_a + 1 + key[old_a] % (key_size - 1)) % key_size;
decrypted[i] = encrypted[i] ^ key[pos_a] ^ key[pos_b];
key[pos_c] = (key[pos_c] << 31) | (key[pos_c] >> 1);
key[pos_a] ^= key[pos_c] ^ i ^ decrypted[i];
}
for(int i = 0; i < 100; i++) printf("%02x ", decrypted[i]);
}
- dchichkov 13y agoAnd there are obvious bugs in that code, for example: pos_a = key[pos_b] % key_size; probably should have been: pos_a = key[pos_b % key_size] % key_size; And so on...
- quelsolaar 13y agoWell your key doesn't have much entropy to begin with.... On a more serious note, the code you written uses a 8bit key. you need to change the line: (key[pos_c] << 31) | (key[pos_c] >> 1); to: (key[pos_c] << 7) | (key[pos_c] >> 1); The algorithm can obviously also be modified to use 64bit chunks that could be faster on 64 bit hardware.
- mtam 13y agoExactly. Unless I misunderstood the code, If the key size is small (compared to the plain text size) and we know the key length, frequency analysis will work just fine.
- quelsolaar 13y agoHow would you go about this? Obviously the key is smaller then the message (otherwise we would use one time pad and be done with it) The key needs to be large enough that A, it cant be guessed, and B so that the branches of possible positions in it quickly becomes unmanageable.
- gmac 13y agoIt sounds like you might enjoy the Matasano Crypto Challenges: http://www.matasano.com/articles/crypto-challenges/ http://www.matasano.com/articles/crypto-challenges/