so i want convert bytes to binary in python, but when i run it, there’s none in the result and i got error:
‘NoneType’ object is not iterable
here’s the code i tried
JavaScript
x
32
32
1
//func biner
2
def biner(password):
3
print(password)
4
password[0]
5
for my_byte in password:
6
print(f'{my_byte:0>8b}', end=' ')
7
8
//func to use the result from func biner
9
def skalar(key, biner):
10
if len(key) <= key_bytes:
11
for x in range(len(key),key_bytes):
12
key = key + "0"
13
14
jumbin2 = len(key)
15
print(jumbin2)
16
17
jumbin = biner
18
print(biner)
19
20
hasilenkrip = ''
21
for a in jumbin:
22
hasilenkrip += a * jumbin2
23
24
print(hasilenkrip)
25
26
//how i called the func
27
enc = b'lx87x87xe6'
28
ky = maru
29
tes = biner(enc)
30
tes1 = skalar(ky, tes)
31
print(tes1)
32
Advertisement
Answer
Your function currently returns None
because there’s no return
statement. Perhaps instead of using print
, you should modify your functions to return an array of outputs.
I suspect what you have in mind is something like this.
JavaScript
1
32
32
1
# //func biner
2
def biner(password):
3
print(password)
4
password[0]
5
return ' '.join(f'{my_byte:0>8b}' for my_byte in password)
6
7
# //func to use the result from func biner
8
def skalar(key, biner):
9
if len(key) <= key_bytes:
10
for x in range(len(key),key_bytes):
11
key = key + "0"
12
13
jumbin2 = len(key)
14
print(jumbin2)
15
16
jumbin = biner
17
print(biner)
18
19
hasilenkrip = ''
20
for a in jumbin:
21
hasilenkrip += a * jumbin2
22
return hasilenkrip
23
24
# print(hasilenkrip)
25
26
# //how i called the func
27
enc = b'lx87x87xe6'
28
ky = maru
29
tes = biner(enc)
30
tes1 = skalar(ky, tes)
31
print(tes1)
32