سؤال

I want to encrypt purely random data with one single key that is shorter than the plaintext.

Should I use AES or another robust encryption algorithm, or can I use OTP, i.e. only xoring (purely random) plaintext with the unique key, block by block?

E.g. data is 1024 bits long and is random. Key is 128-bit long (random too). Is it safe to encrypt data by xoring 8 successive 128-bit blocks with the same key?

هل كانت مفيدة؟

المحلول 2

E.g. data is 1024 bits long and is random. Key is 128-bit long (random too). Is it safe to encrypt data by xoring 8 successive 128-bit blocks with the same key?

If your data is random, then the answer is yes.

You can consider your actual data as OTP key here. It's purely random and is used only once, so there's no way to recover either key or data.

نصائح أخرى

Your question asks " Is it safe to encrypt data by xoring 8 successive 128-bit blocks with the same key?"

This is not a One-Time-Pad. A One-Time-Pad is used once and once only. Any compromise of part of the unencrypted data would allow recovery of all or part of the key, and hence recovery of more of the unencrypted data.

A safe encryption scheme is secure against an attacker knowing part or all of the plaintext: a "known plaintext attack". Your scheme is not safe; it is vulnerable to a known plaintext attack.

If the data itself is random then it is an equally likely to the text space, so any transformation will lead safety. XOR or stream cipher maintains the relation that the blocks have in cipher-text as below..

from Crypto.Cipher import ARC4
key = '1234567812345678'
obj1 = ARC4.new(key)
obj2 = ARC4.new(key)
d1= obj1.encrypt('\x01\x82\x83\x04\x05\x06\x10\x81\x23\x32\x33\x34')
d2= obj2.encrypt('\x81\x02\x83\x84\x85\x86\x90\x01\xa3\xb2\x33\xb4')
print repr(d1)
print repr(d2)


p1='';p2=''
for i in d1:
    if ord(i)>=128: p1+=chr(ord(i)-128)    
    else: p1+=chr(ord(i))

print; print
for i in d2:
    if ord(i)>=128: p2+= chr(ord(i)-128)    
    else: p2+=chr(ord(i))
print p1==p2`    

output:

'\xbaq\xba\xd0\x0c\xb7\xce&\xd3\x019\xfb'
':\xf1\xbaP\x8c7N\xa6S\x819{'


True
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top