Hello,

I have the following Python Code. I would like to replace the block2=(letter1<<16) + (letter2<<8) + 32 using array module. ANy help is appreciated!

for letter1 in range(65,90):

for letter2 in range(65,90):

    ptext=chr(letter1)+chr(letter2)+chr(32)

    block2=(letter1<<16) + (letter2<<8) + 32

    ctext=pow(block2,e,n)           

    table[ptext]=ctext      

You can only index array module array by integer position, I do not see why you would choose to use it.

You mean something like this:

mylist = []
for c1 in range(65, 90):
    for c2 in range(65, 90):
        mylist.append((c1<<16) + (c2<<8) + 32)

print(mylist)

Or this:

import array

myarray = array.array('I', [])
for c1 in range(65, 90):
    for c2 in range(65, 90):
        myarray.append((c1<<16) + (c2<<8) + 32)

print(myarray)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.