python - how to identify elements of a list that corresponds to a criteria and apply a function -


so need program encrypts text file:

for x in range(1):     random_generated=(random.sample(range(33,126), 8))     random_values=(random_generated[0:])     print random_values     ######using random function generate numbers 33 126, 8 times######       ascii="".join([chr(i) in random_values])   ###to convert numbers ascii characters###      print ascii     ###displaying user###         ###source: stackoverflow.com################      offset_factor=(((sum(random_generated[0:]))//8)-32)   ###to calculate offset factor based on generated###     print offset_factor      opentxt= open(filename, 'r').read()   ###source: ubuntuforums.org###     print opentxt    ###opentxt being contents of sample.txt###       converted=[ord(c) c in opentxt]   ###conversion of text list of ascii###     print converted        offset_add=[s + offset_factor s in converted] 

i have gotten point have created list of ascii code based on text file , added randomly generated number each of ascii elements of list. task asks:

develop part of program converts each character in message ascii code , encrypts using following rules:

a. if character space not encrypt character
b. otherwise:
i. convert character ascii code (eg b = 66)
ii. add ascii code offset factor calculated in task 4. if result greater 126 subtract 94 result valid ascii code
iii. convert result equivalent ascii character.

i have done part bi , half of bii other half of bii , biii have problems with.

if question not clear enough please ask explain parts of program.

this when execute program:

1. encrypt message 2. decrypt message 3. quit please enter selection 1 option 1 selected enter filename want encryptsample.txt [35, 121, 52, 49, 63, 56, 58, 47] #y41?8:/ 28 somewhere in la mancha, in place name not care remember,  gentleman lived not long ago, 1 of has lance , ancient shield on shelf , keeps skinny nag , greyhound racing. [83, 111, 109, 101, 119, 104, 101, 114, 101, 32, 105, 110, 32, 108, 97, 32, 77, 97, 110, 99, 104, 97, 44, 32, 105, 110, 32, 97, 32, 112, 108, 97, 99, 101, 32, 119, 104, 111, 115, 101, 32, 110, 97, 109, 101, 32, 73, 32, 100, 111, 32, 110, 111, 116, 32, 99, 97, 114, 101, 32, 116, 111, 32, 114, 101, 109, 101, 109, 98, 101, 114, 44, 32, 97, 32, 103, 101, 110, 116, 108, 101, 109, 97, 110, 32, 108, 105, 118, 101, 100, 32, 110, 111, 116, 32, 108, 111, 110, 103, 32, 97, 103, 111, 44, 32, 111, 110, 101, 32, 111, 102, 32, 116, 104, 111, 115, 101, 32, 119, 104, 111, 32, 104, 97, 115, 32, 97, 32, 108, 97, 110, 99, 101, 32, 97, 110, 100, 32, 97, 110, 99, 105, 101, 110, 116, 32, 115, 104, 105, 101, 108, 100, 32, 111, 110, 32, 97, 32, 115, 104, 101, 108, 102, 32, 97, 110, 100, 32, 107, 101, 101, 112, 115, 32, 97, 32, 115, 107, 105, 110, 110, 121, 32, 110, 97, 103, 32, 97, 110, 100, 32, 97, 32, 103, 114, 101, 121, 104, 111, 117, 110, 100, 32, 102, 111, 114, 32, 114, 97, 99, 105, 110, 103, 46] 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -