diff --git a/1ano/2semestre/labi/tema01/README.md b/1ano/2semestre/labi/tema01/README.md index 5a8d34b..7d14ac8 100755 --- a/1ano/2semestre/labi/tema01/README.md +++ b/1ano/2semestre/labi/tema01/README.md @@ -5,5 +5,7 @@ * [Slides](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/1semestre/iei/tema01/tema-1-criptografia.pdf) * [Guião](https://github.com/TiagoRG/uaveiro-leci/blob/master/1ano/1semestre/iei/tema01/guide-1-cripto.pdf) +### Nota: código bastante incompleto porque a biblioteca do PyCrypto não gosta de trabalhar :skull: + --- *Pode conter erros, caso encontre algum, crie um* [*ticket*](https://github.com/TiagoRG/uaveiro-leci/issues/new) diff --git a/1ano/2semestre/labi/tema01/criptograma b/1ano/2semestre/labi/tema01/criptograma new file mode 100644 index 0000000..e69de29 diff --git a/1ano/2semestre/labi/tema01/src/aes_cypher.py b/1ano/2semestre/labi/tema01/src/aes_cypher.py new file mode 100644 index 0000000..7946728 --- /dev/null +++ b/1ano/2semestre/labi/tema01/src/aes_cypher.py @@ -0,0 +1,12 @@ +import os +import sys +from Crypto.Cipher import AES + + +def main(args=None): + cipher = AES.new(os.urandom(16), AES.MODE_ECB) + print(cipher.encrypt(b'Hello World!')) + + +if __name__ == '__main__': + main(sys.argv[1:]) diff --git a/1ano/2semestre/labi/tema01/src/hash_lib.py b/1ano/2semestre/labi/tema01/src/hash_lib.py new file mode 100644 index 0000000..6f8b368 --- /dev/null +++ b/1ano/2semestre/labi/tema01/src/hash_lib.py @@ -0,0 +1,16 @@ +import hashlib +import sys + + +def main(args=None): + with open(args[0], 'rb') as f: + buffer = f.read(512) + h = hashlib.sha1() + while len(buffer) > 0: + h.update(buffer) + buffer = f.read(512) + print(h.hexdigest()) + + +if __name__ == '__main__': + main(sys.argv[1:]) diff --git a/1ano/2semestre/labi/tema01/src/pycrypto.py b/1ano/2semestre/labi/tema01/src/pycrypto.py new file mode 100644 index 0000000..dea96ad --- /dev/null +++ b/1ano/2semestre/labi/tema01/src/pycrypto.py @@ -0,0 +1,14 @@ +import sys +from Crypto.Hash import SHA256 + + +def main(args=None): + with open(args[0], 'rb') as f: + buffer = f.read() + h = SHA256.new() + h.update(buffer) + print(h.hexdigest()) + + +if __name__ == '__main__': + main(sys.argv[1:]) diff --git a/1ano/2semestre/labi/tema01/src/stream_cyphers.py b/1ano/2semestre/labi/tema01/src/stream_cyphers.py new file mode 100644 index 0000000..d1919b1 --- /dev/null +++ b/1ano/2semestre/labi/tema01/src/stream_cyphers.py @@ -0,0 +1,22 @@ +# Screw 1.4 :skull: +import codecs +import os +import sys +from Crypto.Cipher import ARC4 + + +def main(args=None): + with open(args[0], 'r') as f: + text = f.read(2048) + cipher = ARC4.new(bit_array_from_str(args[1])) + cryptogram = cipher.encrypt(text) + os.write(1, cryptogram) + print() + + +def bit_array_from_str(s): + return [codecs.encode("hex") for elem in s] + + +if __name__ == '__main__': + main(sys.argv[1:])