-1

I am using repl.it Python web IDE, and I really can't solve a problem with it.

I was trying to decode a string, but it seems that there's no way to do it.

import base64

ciphertext = 'FxM7o1wl/7wE9CHPNzbB944feDFXbTSVaJfaLsUMzH5EP4xZRz7Sq8O3y7+jPbXIMVRxpvJZZm7ugqQ4fwpJwtvnB0/BoU+hhGeEZZZ0fFj1irm/zg3bsxOoxBJx4B3U'

ciphertext = base64.b64decode(ciphertext)

print ciphertext

UnicodeDecodeError: 'utf8' codec can't decode byte 0xa3 in position 3: invalid start byte

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
L.Fain
  • 3
  • 1
  • 4
  • Based on your variable name `ciphertext`, I'd guess that your string is still encrypted somehow. You need to decrypt it before you try to print it. If you're just trying to see the intermediate results use `print repr(cipertext)`. – Mark Ransom Nov 01 '16 at 22:03
  • Have you copy-pasted the code? – L.Fain Nov 01 '16 at 22:04

1 Answers1

3

You cannot print ciphertext, since it is a sequence of nonsensical binary bytes, not a text at all (I checked).

Your terminal is assuming that if you print something, that something is UTF8; and it is not. Hence the error. If you had a ciphertext of VGhpcyB3aWxsIGJlIHByaW50ZWQuCg==, that would be printed without problems, since it decodes to valid UTF-8 (valid ASCII-7 actually).

If you want to display the ciphertext, you can replace non-UTF8 characters with spaces, or you can print the ciphertext as hex.

But, actually, what you should really do is decrypt it before printing (also, when you've done it, verify it is a UTF8 text and not, say, encoded in ISO-8859-15 or other charsets. If it is, you can use the appropriate codec; this answer also supplies useful information on charsets).

Community
  • 1
  • 1
LSerni
  • 55,617
  • 10
  • 65
  • 107
  • Any idea on how to decrypt it ? – L.Fain Nov 01 '16 at 22:36
  • It's a 96 binary bytes (thus 768 bits) sequence, apparently random. It might be a **lot** of things, but as ciphers go, I'd go out on a limb and bet on Rijndael cipher. Which, without the encryption key, can't realistically be broken. – LSerni Nov 01 '16 at 23:54
  • Actually i have the key, thats it: fbc8b03597d6ccc89ac9f823 – L.Fain Nov 02 '16 at 12:43
  • 12 bytes, hex encoded. That's strange, and does not look like Rijndael/AES (should be 16). There are other ciphers with key size of 8. I'll look into it tonight. – LSerni Nov 02 '16 at 12:57
  • mmm, you are right. Ive searched for any ROT variant but i am really not sure about that. We can maybe work together ? – L.Fain Nov 02 '16 at 23:18
  • @L.Fain: Rather than guessing (and when it comes to encryption, you can't really guess), why not go to the source where the encoded string is coming from and ask them how it is encoded? – Remy Lebeau Nov 04 '16 at 01:53