commit 984f2bd91f34bd9b93529e539f737dc1ccffa31f Author: lidorkahalani Date: Mon May 6 14:51:06 2024 +0300 A new small project to encrypt_sound.py and decrypt_sound.py 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/.name b/.idea/.name new file mode 100644 index 0000000..c40027d --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +encrypt_sound.py \ No newline at end of file diff --git a/.idea/PycharmProjects.iml b/.idea/PycharmProjects.iml new file mode 100644 index 0000000..8b8c395 --- /dev/null +++ b/.idea/PycharmProjects.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ 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..5895f80 --- /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/_main.py b/_main.py new file mode 100644 index 0000000..5596b44 --- /dev/null +++ b/_main.py @@ -0,0 +1,16 @@ +# This is a sample Python script. + +# Press Shift+F10 to execute it or replace it with your code. +# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings. + + +def print_hi(name): + # Use a breakpoint in the code line below to debug your script. + print(f'Hi, {name}') # Press Ctrl+F8 to toggle the breakpoint. + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + print_hi('PyCharm') + +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ diff --git a/decrypt_sound.py b/decrypt_sound.py new file mode 100644 index 0000000..1a3dcad --- /dev/null +++ b/decrypt_sound.py @@ -0,0 +1,46 @@ +import wave +from Crypto.Cipher import ARC4 + + +def read_wave_file(filename): + """Reads a wave file and returns its data and parameters.""" + with wave.open(filename, 'rb') as wf: + params = wf.getparams() + frames = wf.readframes(params.nframes) + return frames, params + + +def write_wave_file(filename, frames, params): + """Writes wave data to a file.""" + with wave.open(filename, 'wb') as wf: + wf.setparams(params) + wf.writeframes(frames) + + +def rc4_decrypt(data, key): + """Decrypts data using RC4 algorithm.""" + cipher = ARC4.new(key) + return cipher.decrypt(data) + + +def main(): + # Read encrypted sound file + encrypted_filename = 'sound_encrypted.wav' + encrypted_data, params = read_wave_file(encrypted_filename) + + # Get decryption key from user + key = input("Enter 16 ASCII characters for the decryption key: ") + key = key.encode('ascii') + + # Decrypt encrypted sound data + decrypted_data = rc4_decrypt(encrypted_data, key) + + # Write decrypted sound data to file + decrypted_filename = 'sound_decrypted.wav' + write_wave_file(decrypted_filename, decrypted_data, params) + + print("Decryption completed successfully.") + + +if __name__ == "__main__": + main() diff --git a/encrypt_sound.py b/encrypt_sound.py new file mode 100644 index 0000000..67b8ecb --- /dev/null +++ b/encrypt_sound.py @@ -0,0 +1,46 @@ +import wave +from Crypto.Cipher import ARC4 + + +def read_wave_file(filename): + # Reads a wave file and returns its data and parameters + with wave.open(filename, 'rb') as wf: + params = wf.getparams() + frames = wf.readframes(params.nframes) + return frames, params + + +def write_wave_file(filename, frames, params): + # Writes wave data to a file + with wave.open(filename, 'wb') as wf: + wf.setparams(params) + wf.writeframes(frames) + + +def rc4_encrypt(data, key): + # Encrypts data using RC4 algorithm + cipher = ARC4.new(key) + return cipher.encrypt(data) + + +def main(): + # Read sound file + input_filename = 'sound.wav' + sound_data, params = read_wave_file(input_filename) + + # Get encryption key from user + key = input("Enter 16 ASCII characters for the encryption key: ") + key = key.encode('ascii') + + # Encrypt sound data + encrypted_data = rc4_encrypt(sound_data, key) + + # Write encrypted sound data to file + encrypted_filename = 'sound_encrypted.wav' + write_wave_file(encrypted_filename, encrypted_data, params) + + print("Encryption completed successfully.") + + +if __name__ == "__main__": + main() diff --git a/sound.wav b/sound.wav new file mode 100644 index 0000000..4f52e10 Binary files /dev/null and b/sound.wav differ