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      

Recommended Answers

All 2 Replies

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 developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.