Sergidev commited on
Commit
6727e6c
·
verified ·
1 Parent(s): 537892f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -1
app.py CHANGED
@@ -108,7 +108,15 @@ def decrypt_file(filepath, factor):
108
  frames = wav_file.readframes(wav_file.getnframes())
109
 
110
  samples = struct.unpack(f'{len(frames)//2}h', frames)
111
- decrypted_data = ''.join(chr(int(sample / factor)) for sample in samples).encode('latin-1')
 
 
 
 
 
 
 
 
112
 
113
  # Detect original file type
114
  mime = magic.Magic(mime=True)
 
108
  frames = wav_file.readframes(wav_file.getnframes())
109
 
110
  samples = struct.unpack(f'{len(frames)//2}h', frames)
111
+
112
+ # Use a list comprehension with error handling
113
+ decrypted_bytes = bytearray()
114
+ for sample in samples:
115
+ byte_value = int(round(sample / factor))
116
+ # Ensure the byte value is within the valid range (0-255)
117
+ decrypted_bytes.append(max(0, min(byte_value, 255)))
118
+
119
+ decrypted_data = bytes(decrypted_bytes)
120
 
121
  # Detect original file type
122
  mime = magic.Magic(mime=True)