# How to decrypt a code with a given OTP key practically [closed]

For practicing purposes I obtained some cipher and an OTP key. Now my task is to decrypt the cipher using this key.

Both files are .bin files and when I open them with TextEdit there are a huge amount of "strange" symbols (which is obv., since its a cipher text).

But my questions is: How can I get the plaintext using the key?

• Write a program, that reads in both files and XORs the bytes at the same positions? Commented May 4, 2017 at 17:04
• You understand what a OTP is and how they work? It should then follow how to decrypt. Commented May 4, 2017 at 20:27
• Although we usually call it cipher-text, it's actually binary. There are many mistakes by programmers on stackoverflow that treat the ciphertext (or the key for that matter) as text. This may in the worst case lead to missing data (and usually, therefore, the ability to decrypt). Commented May 4, 2017 at 20:28
• @MaartenBodewes that really depends on how the programmer implements it, the last one time pad program I wrote was for text only and so I just used int, char, and modulo 26 like right off the wikipedia example. Commented May 5, 2017 at 7:01
• Hmm, yeah, should have said it is usually binary, especially if XOR is used - an operation on binary input. For modern ciphers it is certainly binary most of the time. Commented May 5, 2017 at 7:46

The "strange" symbols are caused by TextEdit trying to interpret raw binary data as readable characters. Both files You have are just streams of zeroes and ones. When you run a XOR operation on each bit of cipher with corresponding bit of key the result should be the hidden message that should be readable by TextEdit. I usually do things like that by writing a script in Python.

• Thanks for your answer, can you explain me how I can make the file readable? So I can see actually the zeros and ones? The data format is .bin
– Marc
Commented May 4, 2017 at 21:18
• Not exactly zeroes and ones, but You can take a look with HexEdit it will take each eight bits and display them as two digit hexadecimal value. for example 00000000b = 0x00, 00001111b = 0x0F and 11111111b = 0xFF (the "b" means that it's binary notation and "0x" means that it's hexadecimal notation) Python works very well with this hexadecimal notation. Commented May 4, 2017 at 21:26
• You can also use the windows calculator set to "programmer" mode with "hex" setting to manually XOR the values you read from HexEdit. Commented May 4, 2017 at 21:33
• In linux use: \$ xxd -b <filename> Commented May 4, 2017 at 21:50