Typeerror: Ord() Expected String Of Length 1, But Int Found Bse64 From Image
in this case, i want to convert an image to string using base64. then i convert to integer using ord() method. But i got an error. this is my simple code: def input_image_to_string
Solution 1:
Slicing Bytes always return integers in Python3 (already representing the Unicode code point):
>>>x = b'abc'>>>x[1]
98
>>>ord('b')
98
ord()
is obsolete:
...
defHash_the_image(input, panjang):
input = [character for character ininput] # keep ints ...print("Convert to Integers: \n", input)
pesan_block = array_t(uint8_t, panjang)
masukan = pesan_block([uint8(i) for i ininput])
hasil = gimli_hash(masukan, panjang)
print("Hasil hashing: ")
return hasil
...
Out:
31796
Convert to Integers:
[105, 86, ...
Solution 2:
Try the Code Below:
definput_image_to_string():
filename = filedialog.askopenfile(
initialdir="/",
title="Pilih Gambar",
filetypes=(
("png files", "*.png"),
("jpg files", "*.jpg"),
("bmp files", "*.bmp")
)
)
image = filename.name
withopen(image, 'rb') as file:
result = base64.b64encode(file.read())
return result
defHash_the_image(string, panjang):
input = [ord(str(character)) for character in string]
print("Convert to Integers: \n" , input)
pesan_block = array_t(uint8_t, panjang)
masukan = pesan_block([uint8(i) for i ininput])
hasil = gimli_hash(masukan, panjang)
print("Hasil hashing: ")
return hasil
if __name__ == "__main__":
input = input_image_to_string()
panjang = len(input)
print(panjang)
output = Hash_the_image(input, panjang)
print(output)
Post a Comment for "Typeerror: Ord() Expected String Of Length 1, But Int Found Bse64 From Image"