A new small project to encrypt_sound.py and decrypt_sound.py
This commit is contained in:
commit
984f2bd91f
3
.idea/.gitignore
generated
vendored
Normal file
3
.idea/.gitignore
generated
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
|||||||
|
encrypt_sound.py
|
||||||
12
.idea/PycharmProjects.iml
generated
Normal file
12
.idea/PycharmProjects.iml
generated
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
<component name="PyDocumentationSettings">
|
||||||
|
<option name="format" value="PLAIN" />
|
||||||
|
<option name="myDocStringFormat" value="Plain" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
6
.idea/inspectionProfiles/profiles_settings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
4
.idea/misc.xml
generated
Normal file
4
.idea/misc.xml
generated
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/PycharmProjects.iml" filepath="$PROJECT_DIR$/.idea/PycharmProjects.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
16
_main.py
Normal file
16
_main.py
Normal file
@ -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/
|
||||||
46
decrypt_sound.py
Normal file
46
decrypt_sound.py
Normal file
@ -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()
|
||||||
46
encrypt_sound.py
Normal file
46
encrypt_sound.py
Normal file
@ -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()
|
||||||
Loading…
Reference in New Issue
Block a user