From 55dc49ebf07775d84ac948068b376af264950122 Mon Sep 17 00:00:00 2001
From: Lionel <>
Date: Mon, 13 Sep 2021 16:50:11 +0200
Subject: [PATCH] first commit
---
.idea/.gitignore | 3 +
.idea/crypt.iml | 10 +++
.../inspectionProfiles/profiles_settings.xml | 6 ++
.idea/misc.xml | 4 ++
.idea/modules.xml | 8 +++
.idea/vcs.xml | 6 ++
.idea/workspace.xml | 57 +++++++++++++++
README.md | 6 ++
crypt.py | 69 +++++++++++++++++++
main.py | 3 +
original_file.txt | 65 +++++++++++++++++
11 files changed, 237 insertions(+)
create mode 100644 .idea/.gitignore
create mode 100644 .idea/crypt.iml
create mode 100644 .idea/inspectionProfiles/profiles_settings.xml
create mode 100644 .idea/misc.xml
create mode 100644 .idea/modules.xml
create mode 100644 .idea/vcs.xml
create mode 100644 .idea/workspace.xml
create mode 100644 README.md
create mode 100644 crypt.py
create mode 100644 main.py
create mode 100644 original_file.txt
diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/crypt.iml b/.idea/crypt.iml
new file mode 100644
index 0000000..74d515a
--- /dev/null
+++ b/.idea/crypt.iml
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml
new file mode 100644
index 0000000..105ce2d
--- /dev/null
+++ b/.idea/inspectionProfiles/profiles_settings.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..d56657a
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,4 @@
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..8d1d96e
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..94a25f7
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/workspace.xml b/.idea/workspace.xml
new file mode 100644
index 0000000..2864cbb
--- /dev/null
+++ b/.idea/workspace.xml
@@ -0,0 +1,57 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1631795633473
+
+
+ 1631795633473
+
+
+
+
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..76a8f29
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+## Script to recursively encrypt files and folders with AES ##
+
+Source :
+https://eli.thegreenplace.net/2010/06/25/aes-encryption-of-files-in-python-with-pycrypto
+https://pycryptodome.readthedocs.io/en/latest/src/cipher/aes.html
+https://nitratine.net/blog/post/python-encryption-and-decryption-with-pycryptodome/
diff --git a/crypt.py b/crypt.py
new file mode 100644
index 0000000..0139e28
--- /dev/null
+++ b/crypt.py
@@ -0,0 +1,69 @@
+import os, random, struct
+from Crypto.Cipher import AES
+
+def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
+ """ Encrypts a file using AES (CBC mode) with the
+ given key.
+
+ key:
+ The encryption key - a string that must be
+ either 16, 24 or 32 bytes long. Longer keys
+ are more secure.
+
+ in_filename:
+ Name of the input file
+
+ out_filename:
+ If None, '.enc' will be used.
+
+ chunksize:
+ Sets the size of the chunk which the function
+ uses to read and encrypt the file. Larger chunk
+ sizes can be faster for some files and machines.
+ chunksize must be divisible by 16.
+ """
+ if not out_filename:
+ out_filename = in_filename + '.enc'
+
+ iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
+ encryptor = AES.new(key, AES.MODE_CBC, iv)
+ filesize = os.path.getsize(in_filename)
+
+ with open(in_filename, 'rb') as infile:
+ with open(out_filename, 'wb') as outfile:
+ outfile.write(struct.pack('