views:

70

answers:

3

say i encrypt a .doc (or any other type) file and i decrypt it later. however, i cant open it because during the decryption process, [null]s and [DC1] and other highlighted chars were not put back into the file since they are not part of the ASCII characters. how are they written in other programs that compress/encrypt/edit/etc?

im doing this in python, so normally, without editing, i can do:

file1 = open(file,'rb').read()
file2 = open(new_file,'wb')
file2.write(file1)

but this doesnt work if i encrypt and decrypt

+1  A: 

What encryption are you using?
Proper encryption will also encrypt non ascii characters so they can be decrypted properly later

gnibbler
+4  A: 

Nulls and DC1's and so on are definitely part of the ASCII character set, so I don't know what you're talking about. So, for example, consider...:

>>> import pyDes
>>> f = open('afile', 'w')
>>> f.write('Nel mezzo del cammin di nostra vita\n')
>>> f.close()
>>> data = open('afile').read()
>>> encrypted = pyDes.des('mysecret').encrypt(data, padmode=pyDes.PAD_PKCS5)
>>> f = open('encryp', 'wb')
>>> f.write(encrypted)
>>> f.close()
>>> encdata = open('encryp', 'rb').read()
>>> decrypted = pyDes.des('mysecret').decrypt(encdata)
>>> decrypted
'Nel mezzo del cammin di nostra vita\n\x04\x04\x04\x04'

Whatever encryption you're using (pyDes or other) isn't this exactly the kind of thing you're claiming is NOT working...?!

If you're hoping to get help diagnosing the bugs in your code, you'd better post that buggy code, rather than generic descriptions that just don't give enough info to understand your bugs. Though I guess that given your 0% accept rate I shouldn't be so wildly optimistic as to hope you understand anything about how to effectively GET help on stackoverflow!-)

Alex Martelli
I guess he didn't post the encryption code because he's just written it - so it can't have bugs...therefore it must be the file writing!
gnibbler
A: 

im just testing out my codes. i have written a few algorithms (AES,DES,RSA,CAST128, etc), and i know they work for ascii inputs. im just trying to figure out how to get any type of input data to run within algorithms that use values <256. i havent been able to get .exes, .docs with pictures, and other files to decrypt properly

can someone tell me without insulting me???????????? i didnt realize that DC1 is an ascii char because i dont usually see the values printed out.

and i check the algorithms with their test vectors to see if they work. im not stupid enough to say anything that i write must work. or else, i wouldnt be here asking for help

calccrypto
There's a bug in your code. In fact, it is right there on line 31.
GregS
This is not an answer. I think this is more of the question. Please add to the question, and delete this non-answer.
S.Lott