Home > Software design >  Converting int list into base64
Converting int list into base64

Time:12-22

my steps are to :
1. Convert ASCII code into octets

2. Convert octets into sextets

3. Convert sextets into decimals

4. Convert decimals to their equivalent characters in base64 character index table

My problem is that I'm getting different output.

My input is "And"
Insted of "QW5K"
I'm getting "EBY5JA=="

import base64
asciiinput= input("Input Text: ")

bin = [ord(character) for character in asciiinput]
print("input to ascii value: ", bin)


octet = (''.join(map('{:08b}'.format, bin)))
print("Ascii to Octet: ",octet)

ls = list(octet)

test_list = list(map(int, ls))

n = 6
xs = [test_list[i:i   n] for i in range(0, len(ls), n)]
print ("Octets to Sextets  : ",xs)


out = [int(''.join([str(y) for y in x]), 2) for x in xs]
print("Sextets into Decimals: ", out)

base64_code = base64.b64encode(bytes(out))
print(base64_code)

CodePudding user response:

You can do it entirely with the base64 module.

import base64
asciiinput = input("Input Text: ")
base64_str = base64.b64encode(asciiinput.encode()).decode()
print(base64_str)

CodePudding user response:

base64.b64encode(b"And") gives b'QW5k'

  • Related