47 lines
1.1 KiB
Python
47 lines
1.1 KiB
Python
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()
|