Created small app to encrypt and decrypt text!

Hey folks,
i just created little python script to encrypt and decrypt words using AES256bit using openssl. im new at python so it run fine on my linux but im sure you will get some errors because packages and all of that so please while using it tell me what errors you got to try list them in readme file
Thanks!

1 Like

How do you see it being used, in what context

Some feedback:

  1. Coding style: In general, your functions (encrypt and decrypt) should not be included in your try block. In your current code, there is no reason for defining any functions. Your line length should not exceed 79 characters in Python. See also https://www.python.org/dev/peps/pep-0008/. You also don’t need to write myDataFile.close() because with open(filename, mode = READ) as myDataFile : automatically closes the file for you. In with open(filename, mode = READ) as myDataFile : you don’t need to define the mode since read is the default. And why did you choose float for userSelect if you expect int as an input?
  2. Error checking: For instance, there seems to be no check for the missing file. So what happens if a user selects 2 but there is no file? In general, you should use small try-except blocks around critical operations like file I/O operations. Do not put everything in the same try block.
  3. OpenSSL: You are using the -k parameter here, which seems to be deprecated. OpenSSL suggests using -pass, however, your password (the input by the user) is then exposed to the system. So other software on the same machine could see the user’s password. Then, the CBC mode of AES already has some known weaknesses. One other question: Why are you using OpenSSL instead of dedicated Python 3 crypto modules?
  4. No input validation: You assume that the user only enters the password and some text. What happens if the user enters special characters like ', | or "? What happens if the user enters actual Linux commands?

And another tip: Use static code checkers like pylint to debug code before releasing it.

For instance, run pylint theapp.py:

************* Module theapp
theapp.py:4:4: C0326: No space allowed before :
try :
    ^ (bad-whitespace)
theapp.py:5:0: C0301: Line too long (124/100) (line-too-long)
theapp.py:6:0: C0303: Trailing whitespace (trailing-whitespace)
theapp.py:7:23: C0326: No space allowed before :
    if userSelect == 1 :
                       ^ (bad-whitespace)
theapp.py:11:20: C0326: No space allowed before bracket
        def encrypt (encryptedWord, encryptPass) :
                    ^ (bad-whitespace)
theapp.py:11:49: C0326: No space allowed before :
        def encrypt (encryptedWord, encryptPass) :
                                                 ^ (bad-whitespace)
theapp.py:12:0: C0301: Line too long (133/100) (line-too-long)
theapp.py:18:33: C0326: No space allowed around keyword argument assignment
        with open(filename, mode = READ) as myDataFile :
                                 ^ (bad-whitespace)
theapp.py:18:55: C0326: No space allowed before :
        with open(filename, mode = READ) as myDataFile :
                                                       ^ (bad-whitespace)
theapp.py:20:0: C0303: Trailing whitespace (trailing-whitespace)
theapp.py:21:27: C0326: No space allowed before :
        if firstline == "" :
                           ^ (bad-whitespace)
theapp.py:24:13: C0326: No space allowed before :
        else :
             ^ (bad-whitespace)
theapp.py:28:25: C0326: No space allowed before :
    elif userSelect == 2 :
                         ^ (bad-whitespace)
theapp.py:32:20: C0326: No space allowed before bracket
        def decrypt (decryptedWord, decryptPass) :
                    ^ (bad-whitespace)
theapp.py:32:49: C0326: No space allowed before :
        def decrypt (decryptedWord, decryptPass) :
                                                 ^ (bad-whitespace)
theapp.py:33:0: C0301: Line too long (136/100) (line-too-long)
theapp.py:39:33: C0326: No space allowed around keyword argument assignment
        with open(filename, mode = READ) as myDataFile :
                                 ^ (bad-whitespace)
theapp.py:39:55: C0326: No space allowed before :
        with open(filename, mode = READ) as myDataFile :
                                                       ^ (bad-whitespace)
theapp.py:41:0: C0303: Trailing whitespace (trailing-whitespace)
theapp.py:42:27: C0326: No space allowed before :
        if firstline == "" :
                           ^ (bad-whitespace)
theapp.py:45:13: C0326: No space allowed before :
        else :
             ^ (bad-whitespace)
theapp.py:51:7: C0326: No space allowed before :
except :
       ^ (bad-whitespace)
theapp.py:53:58: C0303: Trailing whitespace (trailing-whitespace)
theapp.py:1:0: C0114: Missing module docstring (missing-module-docstring)
theapp.py:51:0: W0702: No exception type(s) specified (bare-except)
theapp.py:5:4: C0103: Constant name "userSelect" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:8:8: C0103: Constant name "encryptWord" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:9:8: C0103: Constant name "encryptPass" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:11:8: C0103: Argument name "encryptedWord" doesn't conform to snake_case naming style (invalid-name)
theapp.py:11:8: C0103: Argument name "encryptPass" doesn't conform to snake_case naming style (invalid-name)
theapp.py:11:8: C0116: Missing function or method docstring (missing-function-docstring)
theapp.py:11:36: W0621: Redefining name 'encryptPass' from outer scope (line 9) (redefined-outer-name)
theapp.py:12:12: C0103: Variable name "myCmd" doesn't conform to snake_case naming style (invalid-name)
theapp.py:16:8: C0103: Constant name "filename" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:19:12: C0103: Constant name "firstline" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:29:8: C0103: Constant name "decryptWord" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:30:8: C0103: Constant name "decryptPass" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:32:8: C0103: Argument name "decryptedWord" doesn't conform to snake_case naming style (invalid-name)
theapp.py:32:8: C0103: Argument name "decryptPass" doesn't conform to snake_case naming style (invalid-name)
theapp.py:32:8: C0116: Missing function or method docstring (missing-function-docstring)
theapp.py:32:36: W0621: Redefining name 'decryptPass' from outer scope (line 30) (redefined-outer-name)
theapp.py:33:12: C0103: Variable name "myCmd" doesn't conform to snake_case naming style (invalid-name)
theapp.py:37:8: C0103: Constant name "filename" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:40:12: C0103: Constant name "firstline" doesn't conform to UPPER_CASE naming style (invalid-name)
theapp.py:52:4: C0103: Constant name "fullerror" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------
Your code has been rated at -0.71/10

in encrypt/decrypt your messages (like PGP)

Yes im working on that

I open the file after it be created so ig error chance will be so small

  1. working on that password thing too

  2. i added float bc i just love it ? lol

  3. i use it because it was easy and i wanted to make offline version of https://cryptotools.net/aes

  4. it should encrypt it too ? i mean characters like ` | and " must work fine as other right ?


Alright after this feedback i feel my app is shit and thinking to use as personal use only (thanks for feedback tho <3)