jcao219 18 Posting Pro in Training

It doesn't take much of a genius to recommend a compiled language, if you want to go for speed alone.

It is also quite evident that it is impractical to use only an interpreted language for this use, if the user is to encrypt files larger than 1mb. A test showed that it took 22 seconds to do something that could be done in less than a second for C.
We are all learning from this testing of program performance.

TrustyTony 888 pyMod Team Colleague Featured Poster

OK, fine. Go ahead and use this nice crypto, as it is easy to use for your files. But please crypt this small file attached with same password and function and save as tonyjv.txt.

Don't need to look it with text editor after crypting, just mail it to me :twisted:

(By the way sorry for poor mobile texting for that original quoted post, I corrected this quote)

Did not fall to that one, congratulation, you are really good with security.
Could you only send that powerpoint file which you emailed me last week encrypted with your password?

What is this program, you ask? Nothing important, just one small function I wrote.

def uncrypt(text, password):
    if len(text) != len(password):
        print 'Inputs must be same length'
    password = [ord(character) for character in password]
    text = [ord(character) ^ password[index] for (index, character) in enumerate(text)]
    
    return ''.join([chr(character_code) for character_code in text])


origfilename='text_100kb.txt'
cryptedfilename='text_100kb.xc'

print uncrypt(open(origfilename,'rb').read()[:512],open(cryptedfilename,'rb').read()[:512])
TrustyTony 888 pyMod Team Colleague Featured Poster

There should be return '' or raise error after line 3, for the if statement to have meaning.

def uncrypt(text, password):
    if len(text) != len(password):
        print 'Inputs must be same length'
        return ''
    password = [ord(character) for character in password]
    text = [ord(character) ^ password[index] for (index, character) in enumerate(text)]
    
    return ''.join([chr(character_code) for character_code in text])


origfilename='text_100kb.txt'
cryptedfilename='text_100kb.xc'

print uncrypt(open(origfilename,'rb').read()[:512],open(cryptedfilename,'rb').read()[:512])
e-papa 13 Posting Pro in Training

Hardly understand you guys, understand the functions and all but the modules, operator, and all, is this module operator used to perform logic operations on data, please reply, I'm new to python and I'm definitely new to the module called operator.

TrustyTony 888 pyMod Team Colleague Featured Poster

operator is used to access the mathematical operators in regular functions to use for example with map or reduce functions. Don't now remember where it was used here though.

To help you dig through the rubbish mails (sorry!), my solution comes up around here:
http://www.daniweb.com/software-development/python/code/216632/1251314#post1251314

kylealanhale 0 Newbie Poster

Wait.. Are you talking about the modulo operator? That's just the more correct term for "remainder". It does the division and returns the remainder. In python, modulo is employed with the percent symbol (%).

Also, here is a slightly more cogent rendition:
http://www.daniweb.com/software-development/python/code/216632/1251707#post1251707

TrustyTony 888 pyMod Team Colleague Featured Poster

Original vegaseat's code used operator module, looks like. I think I can say confidently that my code is more relevant now a days.

Maybe old times it was necessary, now it is possible only to say

a_xor_b = a ^ b
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.