0

I have a script I wrote in Python2 to encrypt files using Crypto.Cipher.ARC4

Now that Python2 is EOL for over a year now, I've been starting to move everything to Python3.

Is it possible to decrypt files encrypted with my script using Python3 (and vice versa)?

Here is my script:

#!/usr/bin/python
import os
from Crypto.Cipher import ARC4

key = "my_redacted_string"
dir = os.path.realpath(__file__)
dir = os.path.dirname(dir)
    # https://stackoverflow.com/questions/4934806
files = os.listdir(dir)
os.chdir(dir)


script_name = __file__
script_name = script_name.split("/")[-1]


proceed = [1, "y", "yes",'1']
for f in files:
    if f == script_name:
        pass
    else:
        string = "Process file? : %s > " % f
        answer = raw_input(string)
        if answer in proceed:
            filo = open(f) # filo == file object, file open
            data = filo.read()
            filo.close()
            e = ARC4.new(key)
            e = e.encrypt(data)
            out_name = "%s.dat" % f
            filo = open(out_name, 'w')
            filo.write(e)
            filo.close()

Here is a script I wrote to decrypt files encrypted with the above script:

#!/usr/bin/python
import os
from Crypto.Cipher import ARC4

key = "my_redacted_string"
dir = os.path.realpath(__file__)
dir = os.path.dirname(dir)
    # https://stackoverflow.com/questions/4934806
files = os.listdir(dir)
os.chdir(dir)

script_name = __file__
script_name = script_name.split("/")[-1]


proceed = [1, "y", "yes",'1']
for f in files:
    if f == script_name:
        pass
    else:
        string = "Process file? : %s > " % f
        answer = raw_input(string)
        if answer in proceed:
            filo = open(f)  # filo == file object, file open
            data = filo.read()
            filo.close()
            d = ARC4.new(key)
            d = d.decrypt(data)
            out_name = os.path.splitext(f)[0]
            print out_name
            filo = open(out_name, 'w')
            filo.write(d)
            filo.close()

I try to make everything cross-platform and incuded #!/usr/bin/python as a habit, but I am using 64-bit Windows 10 on my laptop (I have one Linux box, VMs, and VPSes using Linux and using this script client side so using Windows)

  • ARC4 is just RC4, so you might find it under the shorter name. – rossum Mar 30 '21 at 21:25
  • I notice some encrpytion tutorials say to use `from Crypto.Cipher import ARC4` and other say to `import crpyography` , what's the difference? – Operation420.net Apr 07 '21 at 20:41
  • From what I read RC4 was based on a leak of RSA's RC4 which was (at least at the time) not confirmed or denied by RSA to be their implementation of RC4 and hence was called "Alleged RC4" or ARC4 for short... Was ARC4 confirmed to be RC4 either by RSA or just people analyzing how RC4 works saying about ARC4 "if it walks like a duck, and quacks like a duck..." – Operation420.net Apr 07 '21 at 20:47
  • 1
    ARC4 was later confirmed to be correct. There is no difference between the two; they both have the same weaknesses. – rossum Apr 08 '21 at 08:09

0 Answers0