Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 26th, 2006, 1:49 PM   #1
Sane
Banned
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,101
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Interesting Encryption

I combined a VigenereCypher with Sha-1 - I call it... Vigsha!

Hehe... It also uses base64.

I think this encryption makes it practically impossible to retreive a file's contents without the password.

EDIT I put it up on my website. Check it out: http://jammersbase.ath.cx/vigsha :banana:

Here's the simple code:

from sha import sha
from base64 import encodestring, decodestring

def VigenereCypher(t, k, h=26, o=65):
    g = len(k)
    return ''.join(chr((ord(k[a%g]) + ord(t[a])) % h + o) for a in range(len(t)))

def SolveCypher(t, k, h=26, o=65):
    g = len(k)
    return ''.join(chr((ord(t[a]) - ord(k[a%g])) % h + o) for a in range(len(t))) 

def EncodeFile(settings):
    result = VigenereCypher(encodestring(open(settings['FileIn'], 'r').read()),
                            sha(settings['Password']).hexdigest(),
                            settings['Bits'],
                            settings['Offset'])

    file = open(settings['FileOut'], 'w')
    file.write(result)
    file.close()

def DecodeFile(settings):
    result = SolveCypher(   open(settings['FileIn'], 'r').read(),
                            sha(settings['Password']).hexdigest(),
                            settings['Bits'],
                            settings['Offset'])
                           
    file = open(settings['FileOut'], 'w')
    file.write(decodestring(result))
    file.close()    


if __name__ == '__main__':

    settings1 = {
            'Password' : 'testing vigsha encryption',
            'FileIn'   : 'Vigsha.py',
            'FileOut'  : 'Vigsha_encrypt.py',
            'Bits'     : 255,
            'Offset'   : 0
                }

    settings2 = {
            'Password' : 'testing vigsha encryption',
            'FileIn'   : 'Vigsha_encrypt.py',
            'FileOut'  : 'Vigsha_solved.py',
            'Bits'     : 255,
            'Offset'   : 0
                }

    EncodeFile(settings1)
    DecodeFile(settings2)

Save as 'Vigsha.py' and run to see how it works. For every number you set back the 'bit' variable, you make the encryption stronger, but irreversable. It will error when trying to convert back, because it lost data during the x%h calculation.

I'm sure there are many potential flaws, but as it is currently, it seems to work great.

Last edited by Sane; Feb 26th, 2006 at 2:16 PM.
Sane is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:59 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC