diff --git a/unit02_symmetric/README.md b/unit02_symmetric/README.md index 78e2340..2e84901 100644 --- a/unit02_symmetric/README.md +++ b/unit02_symmetric/README.md @@ -16,9 +16,9 @@ The key concepts involved are defining key entropy; key generators (such as usin ## Presentations -* Week 2 Presentation (PPTX) - Symmetric Key Encryption: [here](https://github.com/billbuchanan/appliedcrypto/blob/master/unit02_symmetric/lecture/chapter02_secret.pptx) -* Week 2 Doodle (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04) -* Week 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/nLRV34K3xIo) +* Unit 2 Presentation (PPTX) - Symmetric Key Encryption: [here](https://github.com/billbuchanan/appliedcrypto/blob/master/unit02_symmetric/lecture/chapter02_secret.pptx) +* Unit 2 Doodle (Video) - Symmetric Key Encryption [here](https://youtu.be/FAjEn-u-qfA) +* Unit 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04) ## Lab diff --git a/unit02_symmetric/lab/possible_ans.md b/unit02_symmetric/lab/possible_ans.md index 3844ae4..8f39553 100644 --- a/unit02_symmetric/lab/possible_ans.md +++ b/unit02_symmetric/lab/possible_ans.md @@ -332,6 +332,65 @@ print(" decrypt: ",plaintext.decode()) A sample is [here](https://replit.com/@billbuchanan/desdec#main.py). +If you want to pass as arguments: + +```Python +from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes +from cryptography.hazmat.primitives import padding +from cryptography.hazmat.backends import default_backend +import sys +import hashlib +import binascii + +val='hello' +password='hello' + +plaintext=val + +def encrypt(plaintext,key, mode): + method=algorithms.TripleDES(key) + cipher = Cipher(method,mode, default_backend()) + encryptor = cipher.encryptor() + ct = encryptor.update(plaintext) + encryptor.finalize() + return(ct) + +def decrypt(ciphertext,key, mode): + method=algorithms.TripleDES(key) + cipher = Cipher(method, mode, default_backend()) + decryptor = cipher.decryptor() + pl = decryptor.update(ciphertext) + decryptor.finalize() + return(pl) + +def pad(data,size=64): + padder = padding.PKCS7(size).padder() + padded_data = padder.update(data) + padded_data += padder.finalize() + return(padded_data) + +def unpad(data,size=64): + padder = padding.PKCS7(size).unpadder() + unpadded_data = padder.update(data) + unpadded_data += padder.finalize() + return(unpadded_data) + + + +if (len(sys.argv)>1): + digest=str(sys.argv[1]) +if (len(sys.argv)>2): + password=str(sys.argv[2]) + + +key = hashlib.sha256(password.encode()).digest()[:16] + +ciphertext=binascii.unhexlify(digest) + +plaintext = decrypt(ciphertext,key,modes.ECB()) + +plaintext = unpad(plaintext) +print(" decrypt: ",plaintext.decode()) +``` + ### E.3 In this case we will convert from Base-64 into a byte array and then try to decrypt: diff --git a/unit02_symmetric/lecture/README.md b/unit02_symmetric/lecture/README.md index b80a121..346f5c7 100644 --- a/unit02_symmetric/lecture/README.md +++ b/unit02_symmetric/lecture/README.md @@ -14,14 +14,8 @@ The key concepts involved in this unit are: ## Presentations -* Week 2 Presentation (PDF) - Symmetric Key Encryption: [here](https://asecuritysite.com/public/chapter02_secret.pdf) -* Week 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04) - - -## Videos -The voice over lecture is here: - -[![](http://img.youtube.com/vi/kdCI5UiVl04/0.jpg)](https://www.youtube.com/watch?v=kdCI5UiVl04 "") - +* Unit 2 Presentation (PPTX) - Symmetric Key Encryption: [here](https://github.com/billbuchanan/appliedcrypto/blob/master/unit02_symmetric/lecture/chapter02_secret.pptx) +* Unit 2 Doodle (Video) - Symmetric Key Encryption [here](https://youtu.be/FAjEn-u-qfA) +* Unit 2 Presentation (Video) - Symmetric Key Encryption [here](https://youtu.be/kdCI5UiVl04)