Welcome, guest | Sign In | My Account | Store | Cart

Here is the way nowdays I am encrypting my data It is simple and effective... Does any encryption-master knows how much effective :)

Python, 43 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import random
#it just gets the octal representation of text and replace /
#by randomly 8 or 9 as octal doesn't have it
def OctalEncode(text):
    s = ''
    #convert to octal string representaion
    for ch in text:
        s = s +'\\%o'%(ord(ch))
    es = ''
    #replace / by 8 or 9
    for ch in s:
        if ch == '\\':
            if random.randrange(2) == 0:
                es=es+'8'
            else:
                es=es+'9'
        else:
            es=es+ch
    return es

#replace 8 and 9 by / and u have ur string back    
def OctalDecode(text):
    ds = text.replace('8','\\')
    ds = ds.replace('9','\\')
    exec 'ds ="'+ds+'"'
    return ds

#octal encode text and passwd and multiply
def Encrypt(text,passwd):
    etext = long(OctalEncode(text))
    epasswd = long(OctalEncode(passwd).replace('8','9'))#must be unique
    e = etext*epasswd
    return str(e)

#divide encode string by octal encode of passwd and u get ur string back
def Decrypt(etext,passwd):
    epasswd = long(OctalEncode(passwd).replace('8','9'))#must be unique
    e = long(etext)/epasswd
    return OctalDecode(str(e))

es = Encrypt('python rules','anurag')
print es
print Decrypt(es,'anurag')

I don't know how much secure it is....to me it seems to be pretty good :) For the person who don't know passwd it will be difficult to factor Encrypt('python rules','anurag') = 74606416841240102050141401351134347444593601585502331623652940177646961 correctly when there is no unique prime factorisation

It converts 'python rules' to octal string and then replace \ by 8 or 9 similarly for passwd 'anurag' a number is generated both numbers are mutiplied to get encrypted string!

2 comments

Anand 18 years, 8 months ago  # | flag

Not a good idea ! This cannot be used for encryption for the simple fact that the size of the 'encrypted' data is tooo large when compared to the original data. As for strength, this will rate 1/10 probably in the pantheon of encryption algorithms.

This is a good candidate for data obfuscation rather than encryption.

Asokan Pichai 16 years, 8 months ago  # | flag

An improvement. We recently needed to generate a set of filenames one per employee; the requirement was that the filename must not be easily correlated to the basic datum - the Employee id. We used this method for the purpose.

While writing the code, I combined the OctalEncode and Encrypt as follows:

def Encode( text ):
      oStr = ''
      for ch in text:
            chv = 8 + random.randrange( 2 )
            oStr = '%s%d%o' %( oStr, chv, ord( ch ) )
      n = long( oStr )
      return str( n * n )
Created by anurag uniyal on Tue, 11 Jun 2002 (PSF)
Python recipes (4591)
anurag uniyal's recipes (12)

Required Modules

Other Information and Tasks