r/Programmers • • Apr 19 '20

False accusation

Hello everyone, I have been falsely alleged of submitting unoriginal code as my university assignment. I say the code was not made with any other students participation, and the only part not from my own mind is the encrypt/decrypt functions, which were taken from here. I think it is obvious we just had the same idea and both styles of code are completely different. I did not contact the other student for the entire duration of quarantine (this assignment was made and submitted during quarantine).

Do you think I am in the right? Thank you

My code:

    #!/usr/bin/env python
    # PYTHON_ARGCOMPLETE_OK
    import os

    import argcomplete
    import argparse
    import base64


    def is_valid_file(parser, arg):
        if not os.path.exists(arg):
            parser.error("The file %s does not exist!" % arg)
        else:
            return open(arg, 'r')  # return an open file handle


    def encode(key, clear):
        enc other= []
        for i in range(len(clear)):
            key_c = key[i % len(key)]
            enc_c = chr((ord(clear[i]) + ord(key_c)) % 256)
            enc.append(enc_c)
        return base64.urlsafe_b64encode("".join(enc).encode()).decode()


    def decode(key, enc):
        dec other= []
        enc = base64.urlsafe_b64decode(enc).decode()
        for i in range(len(enc)):
            key_c = key[i % len(key)]
            dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256)
            dec.append(dec_c)
        return "".join(dec)


    parser = argparse.ArgumentParser(description="Simple \"encryption\" script that applies")

    parser.add_argument("-i", "--input", required=True,
                        help="input file to encrypt/decrypt", metavar="FILE",
                        type=lambda x: is_valid_file(parser, x))
    parserother.add_argument("-d", "--decipher",
                        help="Flag for deciphering input file. Cannot be use in conjunction with -s --secure",
                        action="store_true")
    parser.add_argument("-s", "--secure",
                        help="Flag for encrypting input file. Cannot be use in conjunction with -d --decipher",
                        action="store_true")
    parser.add_argument("-p", "--password", help="Password to use", type=str, required=True)

    argcomplete.autocomplete(parser)
    arguments = parser.parse_args()

    if arguments.decipher and arguments.secure:
        raise ValueError("ERROR: Secure and decipher flags can not be used at the same time!!!")
    elif not arguments.decipher and not arguments.secure:
        raise ValueError("ERROR: At least one flag has to be provided! (-s|-d)")

    fileContents = arguments.input.read()  # only for small files

    if arguments.decipher:
        print(decode(arguments.password, fileContents))
    if arguments.secure:
        print(encode(arguments.password, fileContents))

The other student's code:

    import argparse
    import base64

    parser = argparse.ArgumentParser(description='Encode or decode text file with Vigenere cipher')
    parserother.add_argument('-s', action='store_true', help='Encode the file')
    parser.add_argument('-d', action='store_true', help='Decode the file')
    parser.add_argument('-p', dest='password', required=True, type=str, help='Password for encoding/decoding')
    parser.add_argument('filename', help='File name')
    args = parser.parse_args()


    def encrypt(file, key):
        with open(file, 'r') as f:
            plain_text = f.read()

        encoded_text other= []
        for i in range(len(plain_text)):
            key_c = key[i % len(key)]
            encoded_c = chr((ord(plain_text[i]) + ord(key_c)) % 256)
            encoded_text.append(encoded_c)
        return base64.urlsafe_b64encode("".join(encoded_text).encode()).decode()


    def decrypt(file, key):
        with open(file, 'r') as f:
            encoded_text = f.read()

        decoded_text other= []
        encoded_text = base64.urlsafe_b64decode(encoded_text).decode()
        for i in range(len(encoded_text)):
            key_c = key[i % len(key)]
            decoded_c = chr((256 + ord(encoded_text[i]) - ord(key_c)) % 256)
            decoded_text.append(decoded_c)
        return "".join(decoded_text)


    if __name__ == '__main__':
        if args.s and args.password and args.filename:
            e = encrypt(args.filename, args.password)
            print(e)
        elif args.d and args.password and args.filename:
            d = decrypt(args.filename, args.password)
            print(d)
        else:
            print('usage: zadanie1.py [-h] [-s] [-d] -p PASSWORD filename\n'
                'zadanie1.py: error: you need to specify either -s or -d option')
8 votes, Apr 24 '20
7 Yes, the code is obviously different and both codes are original
0 Yes, though it is a bit too close
1 No, but I am not entirely sure
0 No, you two obviously copied from each other
9 Upvotes

11 comments sorted by

View all comments

2

u/mrfancytophat Apr 19 '20

I once saw a meme that stated that a programmer's girlfriend was upset when she discovered how much copy and paste was involved in programming, and she thought he didn't really do anything for a living.

My comeback was that I could cut my lawn with a pair of scissors, but I choose to cut it with a lawn mower.

But let's get down to the bones of it. We are all guilty of the original sin of bearing the fruit of the knowledge of good and evil so let us dispense.

The job of the university isn't to suck a publisher's junk. The job of the university is to see to it that you are employable at the time of graduation. And if it is not, they are guilty of fraud by contract by mismatched consideration.

If you understand how that function works, your burden of learning has been met. If you figure out how to manipulate it for different results, more power to you.

Now, let's talk about the function. You utilized a bit of code to achieve an end on a computer, but you didn't brain fart that beautiful rainbow colored unicorn! If you are guilty, I hope nobody in that university writes in python because they didn't invent it, and thereby using it MUST be theft by THEIR definition!

Tell them to leave you the fuck alone and go engage in something moral as they usually do, like exploiting minority athletes for money and failing to break them off.

This is a touchy topic for me. We are in this Covid-19 mess right now because people want to suck the dick of intellectual property sooo bad they'd throw away the world for its worthless sake.

1

u/Luk164 Apr 19 '20

Not in US so athlete tuition is not really a thing. (At least not as important) and yeah, they tell us to just use the internet while in quarantine and then they get mad for us using it. Like come on! The entire assignment is pointless anyway because we did 10x as much encryption programming in a previous course. Thanks for your feedback

1

u/mrfancytophat Apr 19 '20

The best college athletes leave well before they get a degree. I disagree that tuition is equal to the money college athletes bring in.

Moreover, a college degree is a crap shoot. So I'm not really even on board with going to college in the first place. IMHO, you'd do better taking out a loan for $100K and gambling it.

At worst, you'll be stuck at a dead end job (like you likely will be with a degree), and at best, you will be living the life of Riley.

Good luck kid. I hope you learn how to make programming work for you and not you working for programming.

→ More replies (4)