Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

TypeError: a bytes-like object is required, not 'str' ?!!

0 votes
asked Jul 4, 2021 by fairbird (120 points)

How to solve it this code with python3 ?!!
 

Dicto = 'W0ZCRQ4JHkdDXFxCUFEfSlVAGkpUXFFcQB1cU0E='

def XorBase64Strings(s1, s2):
    s1 = b64decode(s1)
    s2 = b64decode(s2)
    while len(s2) < len(s1):
        s2 += s2

    out = ''
    for index in range(len(s1)):
        out += chr(s1[index] ^ s2[index])

    return b64encode(out)

Linuxo = b64decode(XorBase64Strings(Dicto, b64encode(schlssl)))
crypttxt = 'W0ZCRQ4JHkdDXFxCUFEfSlVAGkpUXFFcQB1cU0EbcmR9f2F8cBQDARZCUUZKWF9ZG0RLRg=='
txtcrypt = b64decode(XorBase64Strings(crypttxt, b64encode(schlssl)))
crypttxt1 = 'W0ZCRQ4JHkdDXFxCUFEfSlVAGkpUXFFcQB1cU0EbYmN2d38MAwkfRFxGR11WX39kG0RLRg=='
txtcrypt1 = b64decode(XorBase64Strings(crypttxt1, b64encode(schlssl)))
Distcrypt = 'HEdFRxtKWFEZV1tYXl1TCxtETU1ZX1kaYF9HUVxaVR52TkZQX0pZXVdHG2Bsf3lkfHFgc2JlWFNWWlhBGlJRX11KUQ=='
cryptDist = b64decode(XorBase64Strings(Distcrypt, b64encode(schlssl)))

1 Answer

+1 vote
answered Jan 2, 2022 by xDELLx (10,500 points)
Dicto = 'W0ZCRQ4JHkdDXFxCUFEfSlVAGkpUXFFcQB1cU0E='
schlssl="b64encode"
def XorBase64Strings(s1, s2):
    s1 = b64decode(s1)
    s2 = b64decode(s2)
    while len(s2) < len(s1):
        s2 += s2

    out = ''
    for index in range(len(s1)):
        out += chr(ord(s1[index]) ^ ord(s2[index]))

    return b64encode(out)

def b64encode(inp):
    return inp

def b64decode(inp):
    return inp

Linuxo = b64decode(XorBase64Strings(Dicto, b64encode(schlssl)))
crypttxt = 'W0ZCRQ4JHkdDXFxCUFEfSlVAGkpUXFFcQB1cU0EbcmR9f2F8cBQDARZCUUZKWF9ZG0RLRg=='
txtcrypt = b64decode(XorBase64Strings(crypttxt, b64encode(schlssl)))
crypttxt1 = 'W0ZCRQ4JHkdDXFxCUFEfSlVAGkpUXFFcQB1cU0EbYmN2d38MAwkfRFxGR11WX39kG0RLRg=='
txtcrypt1 = b64decode(XorBase64Strings(crypttxt1, b64encode(schlssl)))
Distcrypt = 'HEdFRxtKWFEZV1tYXl1TCxtETU1ZX1kaYF9HUVxaVR52TkZQX0pZXVdHG2Bsf3lkfHFgc2JlWFNWWlhBGlJRX11KUQ=='
cryptDist = b64decode(XorBase64Strings(Distcrypt, b64encode(schlssl)))

Text in RED, i have made liberal assumptions

Text in Green solves the error .

FYI, error i got below:

Traceback (most recent call last):
  File "/tmp/cc.py", line 22, in <module>
    Linuxo = b64decode(XorBase64Strings(Dicto, b64encode(schlssl)))
  File "/tmp/cc.py", line 12, in XorBase64Strings
    out += chr((s1[index]) ^ (s2[index]))
TypeError: unsupported operand type(s) for ^: 'str' and 'str'

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...