1

I'm trying to create a Python Ciphersaber 2 implementation since those that I've found on the net appear to produce gibberish. During the deciphering, I need to be able to xor a single character of a string with a keystream that is represented by integer values, and then cast that result back into a string character. Please note I am entirely new to Python so disregard my awful failures.

Things I've tried so far:

plaintext[i] = ord(msg[i] ^ keystream[i] plaintext[i] = str(plaintext[i]) which resulted in integer values

and

plaintext[i] = ord(msg[i] ^ keystream[i] plaintext[i] = chr(plaintext[i]) which results in values y, \xed \xf4 \x07. Are these byte values?

Appreciate any help

FutureShocked
  • 779
  • 1
  • 10
  • 26

1 Answers1

0

Strings are represented by ASCII values (UTF-8 to be precise) in computer. If you want to xor the plaintext character and keystream, I did recommend you to convert it into range of 26.

E.g. ord('a') is 97 & ord('b') is 98 in ASCII

ord('a') ^ ord('b') = 97 ^ 98 = 3
Note: 3 in ASCII is not an alphabet
a-z lies in range 97 - 122
A-Z lies in range 65 - 100

Try converting them into range of 26 first (using ord('a') for lowercase and ord('A') for uppercase as modulo). Generating cipher - Step 1:

ord('a') % 97 = 0
ord('b') % 97 = 1
0 ^ 1 = 1

Now, add the previous result 1 to ord('a') and then convert it into character. Generating cipher - Step 2:

chr( ord('a') + 1 ) = chr( 97 + 1 ) = chr( 98 ) = 'b'

Similarly, you can reverse the process to decipher.

P.S. I am not aware of the Ciphersaber algorithm.

manishrw
  • 429
  • 5
  • 17