Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Simple block-code encryption algorithm by Hellerick, 2013-06-01
- # http://codepad.org/SulkRkYi
- from random import randint
- code="""z 5 6 7 8 9
- 0 a b c d e
- 1 f g h i j
- 2 k l m n o
- 3 p q r s t
- 4 u v w x y"""
- code=code.split('\n')
- c2l=[]
- for i in code: c2l+=[i.split(' ')]
- l2c={}
- for i in range(len(c2l)):
- for j in range(len(c2l[i])):
- l2c[c2l[i][j]]=[i,j]
- def encrypt(text):
- output=cp=c2l[randint(0,len(c2l)-1)][randint(0,len(c2l[0])-1)]
- text=text.lower()
- for i in range(len(text)):
- if text[i] in l2c:
- di,dj=(l2c[text[i]][0]-l2c[cp][0])%6,(l2c[text[i]][1]-l2c[cp][1])%6
- cp=c2l[di][dj]
- output+=cp
- else:
- output=output+text[i]
- return output
- def decrypt(text):
- cp=text[0]
- text=text[1:]
- output=''
- for i in range(len(text)):
- if text[i] in l2c:
- di,dj=(l2c[text[i]][0]+l2c[cp][0])%6,(l2c[text[i]][1]+l2c[cp][1])%6
- cp=text[i]
- output+=c2l[di][dj]
- else:
- output=output+text[i]
- return output
- thetext="The worst thing about my sister is she's such a GIRL. Well, I'm a girl too, but I'm not a dinky-pinky, silly-frilly girlie girl. Think cupcakes and cuddly teddies and charm bracelets -- that's Melissa. She leaves a little pink trail around the house -- sparkly slides and ribbons and notebooks. You breathe in her revolting scent long after she's gone off to hang out at her friends' houses. She's not allowed to wear real perfume yet, but she's got this rose hand cream that smells really strongly. She doesn't just rub it on her hands, she smoothes it in all over, so she's always slightly slippery. Her lips shine too, because she's forever smearing on lip gloss. She's not really supposed to wear make-up yet either, only for play, but she's got a big plastic bag patterned with pink kittens, and it's crammed full of eye shadows and mascara and blisher. It used to be just Mum's old stuff, but now Melissa spends half her pocket money in Superdrug."
- print ' '+thetext
- print '\n'
- print encrypt(thetext)
- print '\n'
- print ' '+decrypt(encrypt(thetext))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement