开发者

Need XOR Encryption Algorithm Pseudocode

开发者 https://www.devze.com 2022-12-28 15:29 出处:网络
I am trying to find the pseudocode for the XOR encryption algorithm. However I\'ve had no luck so far. Anybody know where I can find it?

I am trying to find the pseudocode for the XOR encryption algorithm. However I've had no luck so far. Anybody know where I can find it?

EDIT: XOR 32 if that helps

EDIT 2: For P开发者_运维百科asswords


Assuming you mean a Vernam cipher, it's just:

for i = 0 to length of input
    output[i] = input[i] xor key[i mod key_length]

Note that this is quite weak unless the key-stream is at least as long as the input, and is never re-used.


The most basic "xor encryption algorithm" is probably one that just XOR's the plaintext with the key, like so:

for each bit of the plaintext:
    ciphertext = bit of plaintext XOR bit of key

where the key just wraps around when it reaches the end.

Since XOR is its own inverse, XORing the ciphertext with the key again in the same fashion will reveal the plaintext.


Do you mean something like?


unsigned char key = 0x7F;  // or any 8-bit value.
//encrypt
for(int i=0; i < strlen(input); i++) { input[i] ^= key; }
//decrypt
for(int i=0; i < strlen(input); i++) { input[i] ^= key; }


For C:

void crypt(char key, char *msg, size_t l)
{
  int i;
  for(i=0; i<l; i++)
  msg[i]^=key;
}

void decrypt(char key, char *msg, size_t l)
{
  crypt(key, msg, l);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号