#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2006
    Posts
    1
    Rep Power
    0

    Chain Block Cipher


    hello there,

    im fairly new to python and im working on Encryption of a Text File.

    i need to encrypt in blocks of 24bits and use space as padding as required - this i understand . the only problem is the very first stage..

    i have for example 24bits (3 plaintext characters)

    "HEL"

    and i need to XOR these with my initialisation vector which is for example 2789284

    how do i perform this eperation?

    thanks in advance if anyone has a minute to help or email me that would be great!!

    andi@undergroundworld.co.uk
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Here is my interpretation of what you asked for.

    python Code:
    vector = 2789284451
    source = 'HELLO world'
     
    # makeKey splits a numeric value into a list of bytes for XORing
    def makeKey(vec):
        v = []
        while vec:
            v.append(vec&255)
            vec >>= 8
        return v
     
     
    #XORstring takes an arbitrary string and arbitrary key list 
    #and returns an XORed string. (okay for ASCII I guess)
    def XORstring(inp,vectors):
        out = []
        while inp:
            for n in vectors:
                out.append(ord(inp[0])^n)
                inp = inp[1:]
                if not inp: break
        return ''.join([ chr(x) for x in out])
     
     
    vparts = makeKey(vector)
     
    output = XORstring(source,vparts)
    print output
    output = XORstring(output,vparts)
    print output
    output = XORstring(output,vparts)
    print output
    output = XORstring(output,vparts)
    print output


    Have fun,

    grim

IMN logo majestic logo threadwatch logo seochat tools logo