0

I'm trying to decrypt a OTP. The key is generated with the following code:

class OTPGenerator(metaclass=Singleton):
_OTP_LEN = 128

def __init__(self):
    self.otp = os.urandom(OTPGenerator._OTP_LEN)

def get_otp(self):
    return self.otp

I get receive the encrypted text thru a socket connection:

b'7Vf\xba\xe1\xb1.\xeb\x05Y\xccL 1\xb2\xec\xb1<0\xb36\xce\xc3\x02\xd6^\xc6z\x15_\x88\x14k\xe9\x8c\xb1\xa5{\xd5\xe3LKE8\x16\xe2\xe1\xf0\xe1+[_\xd47\x13\xd8T\xa7E\x8f\xf3SR\xd1'

And another encrypted text given by be as plaintext:

input = flag
Encrypted Input: b'\t\x17J\x9c'

I'm trying to decode them before XOR-ing them, but they are casted as strings.

Has anyone encountered a similar issue before?

adicpnn
  • 19
  • 2
  • Post text as *text*, please also show what research you've done into solving this yourself. – Sayse Dec 11 '21 at 10:02
  • 1
    If it is a `str` you can't decode it. If it is `bytes` you can. Share the code – azro Dec 11 '21 at 10:02
  • `\xbe` is an invalid start byte for utf-8 anyway, so more investigation into the source of that data might be needed. – Passerby Dec 11 '21 at 10:04
  • Try printing your text without the decode part, you text seem to be decoded already. – Plaix Dec 11 '21 at 10:07

1 Answers1

0

The os.urandom module produces N random bytes with N being passed as argument. In that sense, I'm not sure what you want to decode since this is random data.

In any way, there is this answer that might be what you are looking for, which converts the data produce by os.urandom into a base64 encoded string.

from base64 import b64encode
from os import urandom

random_bytes = urandom(64)
token = b64encode(random_bytes).decode('utf-8')
Melo
  • 113
  • 8