Created
July 23, 2014 15:32
-
-
Save ianjuma/86cd82a11dea64f11eed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
## Encryption and decryption using AES algorithm | |
## with a salting function | |
## two-one way functions defined - encrypt() / decrypt() | |
import hashlib | |
import random | |
import os | |
import base64 | |
""" | |
def getInput(): | |
print "Enter message to encrypt: " | |
message = raw_input() | |
return message | |
message = getInput() | |
some_len = len(message) | |
""" | |
from Crypto.Cipher import AES | |
# key generator | |
public_key = os.urandom(16) | |
print "## Store this key ##" | |
print public_key | |
# random key generator + salt | |
cipher = AES.new(os.urandom(32), AES.MODE_CTR, counter=lambda: public_key) | |
def encrypt(message): | |
""" | |
func to receive a message encrypt and store in a file, for reading | |
""" | |
encryptedMessage = cipher.encrypt(message) | |
return encryptedMessage | |
def decrypt(encryptedMessage): | |
""" | |
func to decrypt a message and store in a file | |
""" | |
message = cipher.decrypt(str(encryptedMessage)) | |
return message | |
x = encrypt("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb") | |
print x | |
y = decrypt(x) | |
print y | |
""" | |
The ideal cryptographic hash function has four main properties: | |
1. it is easy to compute the hash value for any given message | |
2. it is infeasible to generate a message that has a given hash | |
3. it is infeasible to modify a message without changing the hash | |
4. it is infeasible to find two different messages with the same hash. | |
""" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment