Message = base64.urlsafe_b64decode(message).decode()ĭec.append(chr(( 256 + ord(message) - ord(key_c)) % 256))ĭefine a function Mode() that gets the mode entered by the user in the Entry widget and calls the appropriate function as per the selection. Append the character of the Unicode string message decode as shown below. Iterate up to the length of the message and set the modulus of the operation as index and store its value in key_c. Define an empty list and decode the message. Return base64.urlsafe_b64encode( "".join(enc).encode()).decode()ĭefine a function Decode() that accepts a key for encoding and decoding along with the message. def Encode (key, message):Įnc.append(chr((ord(message) + ord(key_c)) % 256)) The base64.urlsafe_b64encode() method encodes this input and replaces - with + and _ with /. Join each element of the list with an empty string and use the encode() method to return a utf-8 encoded version of the string. Use ord() to get the Unicode value of the character and use chr() to get the character that represents the specified value.Īppend this value to the list. Set the index of key as the modulus of the operation and store its value in variable key_c. Define an empty list and iterate up to the length of the message. Of course, spammers are welcome only as readers.Label(root, text= 'Python Message Encoder and Decoder', font= 'arial 25 bold', fg= 'white', bg= "purple").pack()ĭefine a function Encode() that accepts a key for encoding and decoding along with the message. I will be happy to read every comment and, if necessary, I will do my best to respond as quickly as possible. If you have any questions, remarks, need help, or just like this page, please feel free to let me know by leaving a comment using the form bellow. # Python 3.6 - a bytes-like object is required, not 'int' Add new comment # Python 3.6 - b64encode() missing 1 required positional argument: 's'Įxample #6 ( TypeError on wrong argument type): # Python 2.7 - b2a_base64() argument 1 must be string or buffer, not int Print(b64encode(data, '-_')) #-> 'PDw_Pz8-Pg='Įxample #4 (fix the “Synta圎rror: bytes can only contain ASCII literal characters” error on Python 3): from base64 import b64encodeĮxample #5 ( TypeError on missing required argument): # Python 2.7 - b64encode() takes at least 1 argument (0 given) Synta圎rror: bytes can only contain ASCII literal characters.Įxample #2 (fix the “TypeError: a bytes-like object is required, not 'str'” error on Python 3): from base64 import b64encodeĮxample #3 (encode data into a custom Base64 alphabet): from base64 import b64encode
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |