In [ ]:
#encrypt 
openssl aes-128-ecb -in plain.text -out cipher.txt -nosalt -nopad -K "59454c4c4f57205355424d4152494e45"
echo -n "0123456789abcdef0123456789abcdef" | openssl aes-128-ecb -nosalt -nopad -K "59454c4c4f57205355424d4152494e45"  | xxd

#decrypt 
openssl aes-128-ecb -d -in cipher.txt -out dec.txt -nosalt -nopad -K "59454c4c4f57205355424d4152494e45"

In [ ]:
import binascii
from Crypto.Cipher import AES
 
class AESCipher:
    '''
    PyCrypto AES using ECB mode implementation in Python 3.3.  
    This uses very basic 0x00 padding, I would recommend PKCS5/7.
    '''
 
    def __init__(self, key):
        '''
        The constructor takes in a PLAINTEXT string as the key and converts it
        to a byte string to work with throughout the class.
        '''
        # convert key to a plaintext byte string to work with it
        self.key = bytes(key, encoding='utf-8')
        self.BLOCK_SIZE = 16
        
    def __pad(self, raw):
        '''
        This right pads the raw text with 0x00 to force the text to be a
        multiple of 16.  This is how the CFX_ENCRYPT_AES tag does the padding.
        
        @param raw: String of clear text to pad
        @return: byte string of clear text with padding
        '''
        if (len(raw) % self.BLOCK_SIZE == 0):
            return raw
        padding_required = self.BLOCK_SIZE - (len(raw) % self.BLOCK_SIZE)
        padChar = b'\x00'
        data = raw.encode('utf-8') + padding_required * padChar
        return data
    
    def __unpad(self, s):
        '''
        This strips all of the 0x00 from the string passed in. 
        
        @param s: the byte string to unpad
        @return: unpadded byte string
        '''
        s = s.rstrip(b'\x00')
        return s
    
    def encrypt(self, raw):
        '''
        Takes in a string of clear text and encrypts it.
        
        @param raw: a string of clear text
        @return: a string of encrypted ciphertext
        '''
        if (raw is None) or (len(raw) == 0):
            raise ValueError('input text cannot be null or empty set')
        # padding put on before sent for encryption
        raw = self.__pad(raw)
        cipher = AES.AESCipher(self.key[:32], AES.MODE_ECB)
        ciphertext = cipher.encrypt(raw)
        return  binascii.hexlify(bytearray(ciphertext)).decode('utf-8')
    
    def decrypt(self, enc):
        '''
        Takes in a string of ciphertext and decrypts it.
        
        @param enc: encrypted string of ciphertext
        @return: decrypted string of clear text
        '''
        if (enc is None) or (len(enc) == 0):
            raise ValueError('input text cannot be null or empty set')
        enc = binascii.unhexlify(enc)
        cipher = AES.AESCipher(self.key[:32], AES.MODE_ECB)
        enc = self.__unpad(cipher.decrypt(enc))
        return enc.decode('utf-8')

In [42]:
from Crypto.Cipher import AES
from Crypto import Random
key = b'YELLOW SUBMARINE'
#iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_ECB, "")
msg =  cipher.encrypt(b'0123456789abcdef0123456789abcdef')

In [45]:
print ' '.join(x.encode('hex') for x in msg)
#a2a5 8316 129f c596 8341 c78a 0c36 5d20
print len(b'0123456789abcdef0123456789abcdef')


20 1e 80 2f 7b 6a ce 6f 6c d0 a7 43 ba 78 ae ad 20 1e 80 2f 7b 6a ce 6f 6c d0 a7 43 ba 78 ae ad
32

In [44]:
print cipher.block_size
print cipher.mode


16
1

In [46]:
from hex2b64 import b642ascii
#83 d2 41 fb ca 6e 8a e3 3b 6e 55 ae 2c ac 62 af
f=open("7.txt","r")
s=b""
for line in f:
    s+=line.strip()
s=b642ascii(s)
f.close()
key = b'YELLOW SUBMARINE'
#iv = Random.new().read(AES.block_size)
cipher = AES.new(key, AES.MODE_ECB, "ignore")
msg =  cipher.decrypt(s)
print msg


I'm back and I'm ringin' the bell 
A rockin' on the mike while the fly girls yell 
In ecstasy in the back of me 
Well that's my DJ Deshay cuttin' all them Z's 
Hittin' hard and the girlies goin' crazy 
Vanilla's on the mike, man I'm not lazy. 

I'm lettin' my drug kick in 
It controls my mouth and I begin 
To just let it flow, let my concepts go 
My posse's to the side yellin', Go Vanilla Go! 

Smooth 'cause that's the way I will be 
And if you don't give a damn, then 
Why you starin' at me 
So get off 'cause I control the stage 
There's no dissin' allowed 
I'm in my own phase 
The girlies sa y they love me and that is ok 
And I can dance better than any kid n' play 

Stage 2 -- Yea the one ya' wanna listen to 
It's off my head so let the beat play through 
So I can funk it up and make it sound good 
1-2-3 Yo -- Knock on some wood 
For good luck, I like my rhymes atrocious 
Supercalafragilisticexpialidocious 
I'm an effect and that you can bet 
I can take a fly girl and make her wet. 

I'm like Samson -- Samson to Delilah 
There's no denyin', You can try to hang 
But you'll keep tryin' to get my style 
Over and over, practice makes perfect 
But not if you're a loafer. 

You'll get nowhere, no place, no time, no girls 
Soon -- Oh my God, homebody, you probably eat 
Spaghetti with a spoon! Come on and say it! 

VIP. Vanilla Ice yep, yep, I'm comin' hard like a rhino 
Intoxicating so you stagger like a wino 
So punks stop trying and girl stop cryin' 
Vanilla Ice is sellin' and you people are buyin' 
'Cause why the freaks are jockin' like Crazy Glue 
Movin' and groovin' trying to sing along 
All through the ghetto groovin' this here song 
Now you're amazed by the VIP posse. 

Steppin' so hard like a German Nazi 
Startled by the bases hittin' ground 
There's no trippin' on mine, I'm just gettin' down 
Sparkamatic, I'm hangin' tight like a fanatic 
You trapped me once and I thought that 
You might have it 
So step down and lend me your ear 
'89 in my time! You, '90 is my year. 

You're weakenin' fast, YO! and I can tell it 
Your body's gettin' hot, so, so I can smell it 
So don't be mad and don't be sad 
'Cause the lyrics belong to ICE, You can call me Dad 
You're pitchin' a fit, so step back and endure 
Let the witch doctor, Ice, do the dance to cure 
So come up close and don't be square 
You wanna battle me -- Anytime, anywhere 

You thought that I was weak, Boy, you're dead wrong 
So come on, everybody and sing this song 

Say -- Play that funky music Say, go white boy, go white boy go 
play that funky music Go white boy, go white boy, go 
Lay down and boogie and play that funky music till you die. 

Play that funky music Come on, Come on, let me hear 
Play that funky music white boy you say it, say it 
Play that funky music A little louder now 
Play that funky music, white boy Come on, Come on, Come on 
Play that funky music 


In [19]:
s="CRIwqt4+szDbqkNY+I0qbDe3LQz0wiw0SuxBQtAM5TDdMbjCMD/venUDW9BL"[:32]
msg =  cipher.decrypt(s)
print msg


�?��
UEF@�lفsh�d�32��!�ǵRE�

In [31]:



Out[31]:
16

In [ ]: