├── makefile ├── README.md ├── .gitignore ├── examples └── testRC4.cpp ├── LICENSE ├── ARC4.cpp └── ARC4.h /makefile: -------------------------------------------------------------------------------- 1 | CC=g++ 2 | CFLAGS=-I. -Wall -Wextra 3 | 4 | arc4: 5 | $(CC) -c ARC4.cpp $(CFLAGS) -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RC4 encryption 2 | 3 | A simple implementation of RC4 encryption 4 | 5 | ## Why you are not setting the key on the constructor? 6 | 7 | By setting the key on a method I can reset it for a decryption later without creating a new object and paying the burden of initialization -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | -------------------------------------------------------------------------------- /examples/testRC4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using std::string; 8 | using std::cout; 9 | 10 | int main () 11 | { 12 | string someKey = "I_AM_A_KEY"; 13 | string toEncrypt = "I am a plain text string"; 14 | ARC4 rc4; 15 | rc4.setKey((unsigned char*) someKey.c_str(),someKey.length()); 16 | char * enc= (char *) malloc(toEncrypt.size()+1); 17 | char * dec= (char *) malloc(toEncrypt.size()+1); 18 | 19 | rc4.encrypt((char *) toEncrypt.c_str(), enc, toEncrypt.length()); 20 | cout<<" Encrypted result \n"; 21 | cout << enc << "\n"; 22 | 23 | rc4.setKey((unsigned char*) someKey.c_str(),someKey.length()); 24 | rc4.encrypt(enc , dec, toEncrypt.length()); 25 | 26 | cout<<" Decrypted result \n"; 27 | cout << dec << "\n"; 28 | if(strcmp(dec, toEncrypt.c_str()) ==0){ 29 | cout<<"Enctyption successfull!\n"; 30 | } 31 | else{ 32 | cout<<"Something is wrong on the encriptyon!\n"; 33 | } 34 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Fabio Oliveira Costa 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /ARC4.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "ARC4.h" 5 | #include 6 | 7 | using namespace std; 8 | 9 | void ARC4::prga(unsigned char * plaintext,unsigned char * cipher,int size){ 10 | for(int k=0;k