mirror of
https://github.com/billbuchanan/appliedcrypto.git
synced 2026-02-21 11:18:02 +00:00
Update d_01.py
This commit is contained in:
@@ -1,5 +1,35 @@
|
||||
import passlib.hash;
|
||||
string="hello"
|
||||
print ("LM Hash:"+passlib.hash.lmhash.encrypt(string))
|
||||
print ("NT Hash:"+passlib.hash.nthash.encrypt(string))
|
||||
from Crypto.Cipher import AES
|
||||
import hashlib
|
||||
import sys
|
||||
import binascii
|
||||
import Padding
|
||||
|
||||
val='hello'
|
||||
password='hello'
|
||||
|
||||
plaintext=val
|
||||
|
||||
def encrypt(plaintext,key, mode):
|
||||
encobj = AES.new(key,mode)
|
||||
return(encobj.encrypt(plaintext))
|
||||
|
||||
def decrypt(ciphertext,key, mode):
|
||||
encobj = AES.new(key,mode)
|
||||
return(encobj.decrypt(ciphertext))
|
||||
|
||||
key = hashlib.sha256(password.encode()).digest()
|
||||
|
||||
|
||||
plaintext = Padding.appendPadding(plaintext,blocksize=Padding.AES_blocksize,mode='CMS')
|
||||
|
||||
print("After padding (CMS): ",binascii.hexlify(bytearray(plaintext.encode())))
|
||||
|
||||
ciphertext = encrypt(plaintext.encode(),key,AES.MODE_ECB)
|
||||
print("Cipher (ECB): ",binascii.hexlify(bytearray(ciphertext)))
|
||||
|
||||
plaintext = decrypt(ciphertext,key,AES.MODE_ECB)
|
||||
|
||||
plaintext = Padding.removePadding(plaintext.decode(),mode='CMS')
|
||||
print(" decrypt: ",plaintext)
|
||||
|
||||
plaintext=val
|
||||
|
||||
Reference in New Issue
Block a user