Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

RC4 Encryption implement

http://pastebin.com/ETF01RuV
Wow that is ugly as shit. Looks like you're trying to do this with as little whitespace as possible. THat's utterly unnecessary. Expand it, name your variables something meaningful instead of just letters, and use standard things like binascii's hexlify/unhexlify instead of some weird custom shit.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(Oct 26, 2016 11:04 AM)Goodies Wrote:  Wow that is ugly as shit. Looks like you're trying to do this with as little whitespace as possible. THat's utterly unnecessary. Expand it, name your variables something meaningful instead of just letters, and use standard things like binascii's hexlify/unhexlify instead of some weird custom shit.

I like my code to be non dependent on any module when it doesn't need to be. Here is the code rewritten to your criteria, enjoy.

http://pastebin.com/nMwLx26B
(Oct 26, 2016 12:01 PM)M5DD Wrote:  I like my code to be non dependent on any module when it doesn't need to be. Here is the code rewritten to your criteria, enjoy.

http://pastebin.com/XKn6vWa8

That looks much better aesthetically.
Also, since binascii is apart of the standard library, it's not really a dependency...

Now, the gripe I have is that I'm not sure you're aware of how RC4 is supposed to function. It's a stream cipher meaning each time I use it, it should give me the next part of the stream. In Python, I'd probably implement it as a generator (or at least an object with a_next_ function defined) that simple takes the key on initialization and returns the next byte.

Finally, it wouldn't work with Python3 which should really be your primary concern now.
SRPP Discord Server

I am a professional network/cloud security architect.
My Old Tutorials
(Oct 26, 2016 12:19 PM)Goodies Wrote:  That looks much better aesthetically.
Also, since binascii is apart of the standard library, it's not really a dependency...

Now, the gripe I have is that I'm not sure you're aware of how RC4 is supposed to function. It's a stream cipher meaning each time I use it, it should give me the next part of the stream. In Python, I'd probably implement it as a generator (or at least an object with a_next_ function defined) that simple takes the key on initialization and returns the next byte.

Finally, it wouldn't work with Python3 which should really be your primary concern now.

I'm learning cryptography, essentially, I converted pseudo code to python code, I'm still grasping the basics of ciphers, so please forgive me there. As for compatibility for python 3, which I'm not familiar with, I'll try to fix it, however I'll look at the python changelog and attempt a solution. Thanks for the suggestions, I've been looking to improve my code.


Update: I managed to fix the decryption function for 3.x, however the encrypt function is still pretty funky, am working on it.
rc4 should enc dec with the same function
[Image: bitcoin.png] Be Nice For Once 15hVUVz7xA4kazHdk2BuErENGCskVwjYXP
(Oct 26, 2016 01:22 PM)HFDone Wrote:  rc4 should enc dec with the same function

You're correct, however the conversion to hex and conversion back to decimal require two functions, I will alter accordingly, thanks. This is also compatible with python 3.x

http://pastebin.com/ETF01RuV
I'm sorry for being a script kiddie but what does this do?
(Oct 27, 2016 03:46 AM)SilenceHacker Wrote:  I'm sorry for being a script kiddie but what does this do?

It allows you to encrypt / decrypt with the same function, it's rather useful for small programs when you need a simple encryption method without external modules. Try encrypting "test" with key "test", then decrypting the result with the same function and the same key.


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by yuumiJun 5, 2022 06:30 PM 22 554 Jun 5, 2022 06:30 PM
Last Post: yuumi
[C#] by fallagFeb 13, 2021 10:44 PM 9 399 Feb 13, 2021 10:44 PM
Last Post: uint32
[Python] by SмℯґƒDec 10, 2020 12:52 PM 6 218 Dec 10, 2020 12:52 PM
Last Post: Sмℯґƒ