├── .gitignore ├── Encryption_Algorithms ├── AES Counter_Mode ├── AES.H ├── AES_Code.java ├── Affine_PlayFair_Cipher.ipynb ├── COMPILE.BAT ├── DEBUG.H ├── MD5 Hashing.py ├── One-Time pad Encryption │ ├── README.md │ ├── otp.py │ └── requirements.txt ├── PLATFORM.H ├── README ├── RSA │ ├── enc_dec_RSA.cpp │ └── encryption.md ├── SHA_Hashing.py ├── TABLE.H ├── TST2FISH.C ├── TST2FISH.EXE ├── TWOFISH.C ├── Vernam_one_time_pad.ipynb ├── cieser-cipher-encryption_in_c.c └── cypherTextUsingKey(Basic).ipynb ├── LICENSE ├── Learning Resources ├── LearningResources.md ├── Links for Introduction to Cybersecurity.md ├── Mobile Locator.md ├── PenTest Methodologies.md ├── PenTest Resources.md └── pdfs │ ├── Black Hat Python.pdf │ ├── Ehthical hacking book tutorials point.pdf │ ├── Ethical Hacking and Penetration Testing Guide.pdf │ ├── The Hacker Playbook 2 - Practical Guide To Penetration Testing.pdf │ └── [Bookflare.net] - Cryptors Hacker Manual.pdf ├── Projects ├── .idea │ ├── Security_Hacking_Scripts.iml │ ├── inspectionProfiles │ │ └── profiles_settings.xml │ ├── modules.xml │ ├── vcs.xml │ └── workspace.xml └── EncryptedChatUsingBasicCypherAlgo │ ├── README.md │ ├── index.html │ ├── package-lock.json │ ├── package.json │ ├── plan.txt │ ├── public │ ├── client.js │ ├── style.css │ └── wassup.png │ └── server.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .Ds_store -------------------------------------------------------------------------------- /Encryption_Algorithms/AES Counter_Mode: -------------------------------------------------------------------------------- 1 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 2 | /* Web worker to encrypt/decrypt files using AES counter-mode (c) Chris Veness 2016-2018 */ 3 | /* MIT Licence */ 4 | /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 5 | 6 | import AesCtr from './js/crypto/aes-ctr.js'; 7 | 8 | /** 9 | * Web worker to encrypt/decrypt files using AES counter-mode. 10 | * 11 | * @param {string} msg.data.op - 'encrypt' or 'decrypt'. 12 | * @param {File} msg.data.file - File to be encrypted or decrypted. 13 | * @param {string} msg.data.password - Password to use to encrypt/decrypt file. 14 | * @param {number} msg.data.bits - Number of bits to use for key. 15 | * @returns {ciphertext|plaintext} - Blob containing encrypted ciphertext / decrypted plaintext. 16 | * 17 | * @example 18 | * var worker = new Worker('aes-ctr-file-webworker.js'); 19 | * var file = this.files[0]; 20 | * worker.postMessage({ op:'encrypt', file:file, password:'L0ck it up ŝaf3', bits:256 }); 21 | * worker.onmessage = function(msg) { 22 | * if (msg.data.progress != 'complete') { 23 | * $('progress').val(msg.data.progress * 100); // update progress bar 24 | * } 25 | * if (msg.data.progress == 'complete') { 26 | * saveAs(msg.data.ciphertext, file.name+'.encrypted'); // save encrypted file 27 | * } 28 | * } 29 | * 30 | * Note saveAs() cannot run in web worker, so encrypted/decrypted file has to be passed back to UI 31 | * thread to be saved. 32 | * 33 | * TODO: error handling on failed decryption 34 | */ 35 | onmessage = function(msg) { 36 | switch (msg.data.op) { 37 | case 'encrypt': 38 | var reader = new FileReaderSync(); 39 | var plaintext = reader.readAsText(msg.data.file, 'utf-8'); 40 | var ciphertext = AesCtr.encrypt(plaintext, msg.data.password, msg.data.bits); 41 | // return encrypted file as Blob; UI thread can then use saveAs() 42 | var blob = new Blob([ciphertext], { type: 'text/plain' }); 43 | self.postMessage({ progress: 'complete', ciphertext: blob }); 44 | break; 45 | case 'decrypt': 46 | var reader = new FileReaderSync(); 47 | var ciphertext = reader.readAsText(msg.data.file, 'iso-8859-1'); 48 | var plaintext = AesCtr.decrypt(ciphertext, msg.data.password, msg.data.bits); 49 | // return decrypted file as Blob; UI thread can then use saveAs() 50 | var blob = new Blob([plaintext], { type: 'application/octet-stream' }); 51 | self.postMessage({ progress: 'complete', plaintext: blob }); 52 | break; 53 | } 54 | }; 55 | -------------------------------------------------------------------------------- /Encryption_Algorithms/AES.H: -------------------------------------------------------------------------------- 1 | /* aes.h */ 2 | 3 | /* ---------- See examples at end of this file for typical usage -------- */ 4 | 5 | /* AES Cipher header file for ANSI C Submissions 6 | Lawrence E. Bassham III 7 | Computer Security Division 8 | National Institute of Standards and Technology 9 | 10 | This sample is to assist implementers developing to the 11 | Cryptographic API Profile for AES Candidate Algorithm Submissions. 12 | Please consult this document as a cross-reference. 13 | 14 | ANY CHANGES, WHERE APPROPRIATE, TO INFORMATION PROVIDED IN THIS FILE 15 | MUST BE DOCUMENTED. CHANGES ARE ONLY APPROPRIATE WHERE SPECIFIED WITH 16 | THE STRING "CHANGE POSSIBLE". FUNCTION CALLS AND THEIR PARAMETERS 17 | CANNOT BE CHANGED. STRUCTURES CAN BE ALTERED TO ALLOW IMPLEMENTERS TO 18 | INCLUDE IMPLEMENTATION SPECIFIC INFORMATION. 19 | */ 20 | 21 | /* Includes: 22 | Standard include files 23 | */ 24 | 25 | #include 26 | #include "platform.h" /* platform-specific defines */ 27 | 28 | /* Defines: 29 | Add any additional defines you need 30 | */ 31 | 32 | #define DIR_ENCRYPT 0 /* Are we encrpyting? */ 33 | #define DIR_DECRYPT 1 /* Are we decrpyting? */ 34 | #define MODE_ECB 1 /* Are we ciphering in ECB mode? */ 35 | #define MODE_CBC 2 /* Are we ciphering in CBC mode? */ 36 | #define MODE_CFB1 3 /* Are we ciphering in 1-bit CFB mode? */ 37 | 38 | #define TRUE 1 39 | #define FALSE 0 40 | 41 | #define BAD_KEY_DIR -1 /* Key direction is invalid (unknown value) */ 42 | #define BAD_KEY_MAT -2 /* Key material not of correct length */ 43 | #define BAD_KEY_INSTANCE -3 /* Key passed is not valid */ 44 | #define BAD_CIPHER_MODE -4 /* Params struct passed to cipherInit invalid */ 45 | #define BAD_CIPHER_STATE -5 /* Cipher in wrong state (e.g., not initialized) */ 46 | 47 | /* CHANGE POSSIBLE: inclusion of algorithm specific defines */ 48 | /* TWOFISH specific definitions */ 49 | #define MAX_KEY_SIZE 64 /* # of ASCII chars needed to represent a key */ 50 | #define MAX_IV_SIZE 16 /* # of bytes needed to represent an IV */ 51 | #define BAD_INPUT_LEN -6 /* inputLen not a multiple of block size */ 52 | #define BAD_PARAMS -7 /* invalid parameters */ 53 | #define BAD_IV_MAT -8 /* invalid IV text */ 54 | #define BAD_ENDIAN -9 /* incorrect endianness define */ 55 | #define BAD_ALIGN32 -10 /* incorrect 32-bit alignment */ 56 | 57 | #define BLOCK_SIZE 128 /* number of bits per block */ 58 | #define MAX_ROUNDS 16 /* max # rounds (for allocating subkey array) */ 59 | #define ROUNDS_128 16 /* default number of rounds for 128-bit keys*/ 60 | #define ROUNDS_192 16 /* default number of rounds for 192-bit keys*/ 61 | #define ROUNDS_256 16 /* default number of rounds for 256-bit keys*/ 62 | #define MAX_KEY_BITS 256 /* max number of bits of key */ 63 | #define MIN_KEY_BITS 128 /* min number of bits of key (zero pad) */ 64 | #define VALID_SIG 0x48534946 /* initialization signature ('FISH') */ 65 | #define MCT_OUTER 400 /* MCT outer loop */ 66 | #define MCT_INNER 10000 /* MCT inner loop */ 67 | #define REENTRANT 1 /* nonzero forces reentrant code (slightly slower) */ 68 | 69 | #define INPUT_WHITEN 0 /* subkey array indices */ 70 | #define OUTPUT_WHITEN ( INPUT_WHITEN + BLOCK_SIZE/32) 71 | #define ROUND_SUBKEYS (OUTPUT_WHITEN + BLOCK_SIZE/32) /* use 2 * (# rounds) */ 72 | #define TOTAL_SUBKEYS (ROUND_SUBKEYS + 2*MAX_ROUNDS) 73 | 74 | /* Typedefs: 75 | Typedef'ed data storage elements. Add any algorithm specific 76 | parameters at the bottom of the structs as appropriate. 77 | */ 78 | 79 | typedef unsigned char BYTE; 80 | typedef unsigned long DWORD; /* 32-bit unsigned quantity */ 81 | typedef DWORD fullSbox[4][256]; 82 | 83 | /* The structure for key information */ 84 | typedef struct 85 | { 86 | BYTE direction; /* Key used for encrypting or decrypting? */ 87 | #if ALIGN32 88 | BYTE dummyAlign[3]; /* keep 32-bit alignment */ 89 | #endif 90 | int keyLen; /* Length of the key */ 91 | char keyMaterial[MAX_KEY_SIZE+4];/* Raw key data in ASCII */ 92 | 93 | /* Twofish-specific parameters: */ 94 | DWORD keySig; /* set to VALID_SIG by makeKey() */ 95 | int numRounds; /* number of rounds in cipher */ 96 | DWORD key32[MAX_KEY_BITS/32]; /* actual key bits, in dwords */ 97 | DWORD sboxKeys[MAX_KEY_BITS/64];/* key bits used for S-boxes */ 98 | DWORD subKeys[TOTAL_SUBKEYS]; /* round subkeys, input/output whitening bits */ 99 | #if REENTRANT 100 | fullSbox sBox8x32; /* fully expanded S-box */ 101 | #if defined(COMPILE_KEY) && defined(USE_ASM) 102 | #undef VALID_SIG 103 | #define VALID_SIG 0x504D4F43 /* 'COMP': C is compiled with -DCOMPILE_KEY */ 104 | DWORD cSig1; /* set after first "compile" (zero at "init") */ 105 | void *encryptFuncPtr; /* ptr to asm encrypt function */ 106 | void *decryptFuncPtr; /* ptr to asm decrypt function */ 107 | DWORD codeSize; /* size of compiledCode */ 108 | DWORD cSig2; /* set after first "compile" */ 109 | BYTE compiledCode[5000]; /* make room for the code itself */ 110 | #endif 111 | #endif 112 | } keyInstance; 113 | 114 | /* The structure for cipher information */ 115 | typedef struct 116 | { 117 | BYTE mode; /* MODE_ECB, MODE_CBC, or MODE_CFB1 */ 118 | #if ALIGN32 119 | BYTE dummyAlign[3]; /* keep 32-bit alignment */ 120 | #endif 121 | BYTE IV[MAX_IV_SIZE]; /* CFB1 iv bytes (CBC uses iv32) */ 122 | 123 | /* Twofish-specific parameters: */ 124 | DWORD cipherSig; /* set to VALID_SIG by cipherInit() */ 125 | DWORD iv32[BLOCK_SIZE/32]; /* CBC IV bytes arranged as dwords */ 126 | } cipherInstance; 127 | 128 | /* Function protoypes */ 129 | int makeKey(keyInstance *key, BYTE direction, int keyLen, char *keyMaterial); 130 | 131 | int cipherInit(cipherInstance *cipher, BYTE mode, char *IV); 132 | 133 | int blockEncrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, 134 | int inputLen, BYTE *outBuffer); 135 | 136 | int blockDecrypt(cipherInstance *cipher, keyInstance *key, BYTE *input, 137 | int inputLen, BYTE *outBuffer); 138 | 139 | int reKey(keyInstance *key); /* do key schedule using modified key.keyDwords */ 140 | 141 | /* API to check table usage, for use in ECB_TBL KAT */ 142 | #define TAB_DISABLE 0 143 | #define TAB_ENABLE 1 144 | #define TAB_RESET 2 145 | #define TAB_QUERY 3 146 | #define TAB_MIN_QUERY 50 147 | int TableOp(int op); 148 | 149 | 150 | #define CONST /* helpful C++ syntax sugar, NOP for ANSI C */ 151 | 152 | #if BLOCK_SIZE == 128 /* optimize block copies */ 153 | #define Copy1(d,s,N) ((DWORD *)(d))[N] = ((DWORD *)(s))[N] 154 | #define BlockCopy(d,s) { Copy1(d,s,0);Copy1(d,s,1);Copy1(d,s,2);Copy1(d,s,3); } 155 | #else 156 | #define BlockCopy(d,s) { memcpy(d,s,BLOCK_SIZE/8); } 157 | #endif 158 | 159 | 160 | #ifdef TEST_2FISH 161 | /* ----- EXAMPLES ----- 162 | 163 | Unfortunately, the AES API is somewhat clumsy, and it is not entirely 164 | obvious how to use the above functions. In particular, note that 165 | makeKey() takes an ASCII hex nibble key string (e.g., 32 characters 166 | for a 128-bit key), which is rarely the way that keys are internally 167 | represented. The reKey() function uses instead the keyInstance.key32 168 | array of key bits and is the preferred method. In fact, makeKey() 169 | initializes some internal keyInstance state, then parse the ASCII 170 | string into the binary key32, and calls reKey(). To initialize the 171 | keyInstance state, use a 'dummy' call to makeKey(); i.e., set the 172 | keyMaterial parameter to NULL. Then use reKey() for all key changes. 173 | Similarly, cipherInit takes an IV string in ASCII hex, so a dummy setup 174 | call with a null IV string will skip the ASCII parse. 175 | 176 | Note that CFB mode is not well tested nor defined by AES, so using the 177 | Twofish MODE_CFB it not recommended. If you wish to implement a CFB mode, 178 | build it external to the Twofish code, using the Twofish functions only 179 | in ECB mode. 180 | 181 | Below is a sample piece of code showing how the code is typically used 182 | to set up a key, encrypt, and decrypt. Error checking is somewhat limited 183 | in this example. Pseudorandom bytes are used for all key and text. 184 | 185 | If you compile TWOFISH2.C or TWOFISH.C as a DOS (or Windows Console) app 186 | with this code enabled, the test will be run. For example, using 187 | Borland C, you would compile using: 188 | BCC32 -DTEST_2FISH twofish2.c 189 | to run the test on the optimized code, or 190 | BCC32 -DTEST_2FISH twofish.c 191 | to run the test on the pedagogical code. 192 | 193 | */ 194 | 195 | #include 196 | #include 197 | #include 198 | #include 199 | 200 | #define MAX_BLK_CNT 4 /* max # blocks per call in TestTwofish */ 201 | int TestTwofish(int mode,int keySize) /* keySize must be 128, 192, or 256 */ 202 | { /* return 0 iff test passes */ 203 | keyInstance ki; /* key information, including tables */ 204 | cipherInstance ci; /* keeps mode (ECB, CBC) and IV */ 205 | BYTE plainText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; 206 | BYTE cipherText[MAX_BLK_CNT*(BLOCK_SIZE/8)]; 207 | BYTE decryptOut[MAX_BLK_CNT*(BLOCK_SIZE/8)]; 208 | BYTE iv[BLOCK_SIZE/8]; 209 | int i,byteCnt; 210 | 211 | if (makeKey(&ki,DIR_ENCRYPT,keySize,NULL) != TRUE) 212 | return 1; /* 'dummy' setup for a 128-bit key */ 213 | if (cipherInit(&ci,mode,NULL) != TRUE) 214 | return 1; /* 'dummy' setup for cipher */ 215 | 216 | for (i=0;i-1(c-b) (mod m)" 14 | ] 15 | }, 16 | { 17 | "cell_type": "code", 18 | "execution_count": 5, 19 | "metadata": {}, 20 | "outputs": [ 21 | { 22 | "name": "stdout", 23 | "output_type": "stream", 24 | "text": [ 25 | "Enter the value of key a: 17\n", 26 | "Enter the value of key b: 20\n", 27 | "Enter the Message: hello\n", 28 | "Choose:\n", 29 | "1: Encrypt Message\n", 30 | "2: Decrypt Message\n", 31 | "1\n", 32 | "Encrypted Message: jkzzy\n" 33 | ] 34 | } 35 | ], 36 | "source": [ 37 | "a=int(input(\"Enter the value of key a: \"))\n", 38 | "b=int(input(\"Enter the value of key b: \"))\n", 39 | "msg=input(\"Enter the Message: \")\n", 40 | "option=int(input(\"Choose:\\n1: Encrypt Message\\n2: Decrypt Message\\n\"))\n", 41 | "def mulinverse():\n", 42 | " for i in range(26):\n", 43 | " if(a*i%26==1):\n", 44 | " return i;\n", 45 | "a_inv=mulinverse()\n", 46 | " \n", 47 | "def encrypt(ch):\n", 48 | " if(ch.isupper()):\n", 49 | " return chr((((ord(ch)-65)*a)+b)%26+65)\n", 50 | " else:\n", 51 | " return chr((((ord(ch)-97)*a)+b)%26+97)\n", 52 | "def decrypt(ch):\n", 53 | " if(ch.isupper()):\n", 54 | " return chr((a_inv*((ord(ch)-65)-b))%26+65)\n", 55 | " else:\n", 56 | " return chr(a_inv*((ord(ch)-97)-b)%26+97)\n", 57 | " \n", 58 | "if(option==1):\n", 59 | " encmsg=\"\"\n", 60 | " for i in msg:\n", 61 | " if(i==\" \"):\n", 62 | " encmsg+=i\n", 63 | " else: \n", 64 | " encmsg+=encrypt(i)\n", 65 | " print(\"Encrypted Message: \",encmsg) \n", 66 | "else:\n", 67 | " decmsg=\"\"\n", 68 | " for i in msg:\n", 69 | " if(i==\" \"):\n", 70 | " decmsg+=i\n", 71 | " else: \n", 72 | " encmsg+=decrypt(i)\n", 73 | " print(\"Decrypted Message: \",decmsg)\n", 74 | " " 75 | ] 76 | }, 77 | { 78 | "cell_type": "markdown", 79 | "metadata": {}, 80 | "source": [ 81 | "# Playfair Cipher:\n", 82 | "The Playfair cipher encrypts pairs of letters (digraphs), instead of\n", 83 | "single letters as is the case with simpler substitution ciphers such as the Caesar Cipher.\n", 84 | "The playfair cipher starts with creating a key table. The key table is a 5×5 grid of letters\n", 85 | "that will act as the key for encrypting your plaintext.\n", 86 | "The Playfair cipher uses a few simple rules relating to where the letters of each digraph\n", 87 | "are in relation to each other. The rules are:\n", 88 | "- If both letters are in the same column, take the letter below each one (going back to the top if at the bottom)\n", 89 | "- If both letters are in the same row, take the letter to the right of each one (going back to the left if at the farthest right)\n", 90 | "- If neither of the preceding two rules are true, form a rectangle with the two letters and take the letters on the horizontal opposite corner of the rectangle" 91 | ] 92 | }, 93 | { 94 | "cell_type": "code", 95 | "execution_count": 4, 96 | "metadata": {}, 97 | "outputs": [ 98 | { 99 | "name": "stdout", 100 | "output_type": "stream", 101 | "text": [ 102 | "Enter Key: monarchy\n", 103 | "Enter Message: instruments\n", 104 | "Encrypted Message: gatlmzclrqtx\n" 105 | ] 106 | } 107 | ], 108 | "source": [ 109 | "key=input(\"Enter Key: \")\n", 110 | "msg=input(\"Enter Message: \")\n", 111 | "alphas={'a':0,'b':0,'c':0,'d':0,'e':0,'f':0,'g':0,'h':0,'i':0,'k':0,'l':0,'m':0,'n':0,'o':0,'p':0,'q':0,'r':0,'s':0,'t':0,'u':0,'v':0,'w':0,'x':0,'y':0,'z':0}\n", 112 | "keylist=[['' for j in range(5)] for i in range(5)]\n", 113 | "lst=[]\n", 114 | "\n", 115 | "for i in key:\n", 116 | " if(i=='j'):\n", 117 | " lst.append('i')\n", 118 | " alphas['i']=1\n", 119 | " else:\n", 120 | " lst.append(i)\n", 121 | " alphas[i]=1\n", 122 | " \n", 123 | "for i in alphas:\n", 124 | " if(alphas[i]==0):\n", 125 | " lst.append(i)\n", 126 | "k=0\n", 127 | "posMap={}\n", 128 | "for i in range(5):\n", 129 | " for j in range(5):\n", 130 | " keylist[i][j]=lst[k]\n", 131 | " posMap[lst[k]]=[i,j]\n", 132 | " k+=1\n", 133 | " \n", 134 | "msg=msg.replace('j','i')\n", 135 | "msg=msg.replace(' ','')\n", 136 | "\n", 137 | "if(len(msg)%2!=0):\n", 138 | " msg+='z';\n", 139 | " \n", 140 | "encmsg=\"\" \n", 141 | "for i in range(0,len(msg)-1,2):\n", 142 | " if(posMap[msg[i]][0]==posMap[msg[i+1]][0]):\n", 143 | " encmsg+=keylist[posMap[msg[i]][0]][(posMap[msg[i]][1]+1)%5]\n", 144 | " encmsg+=keylist[posMap[msg[i+1]][0]][(posMap[msg[i+1]][1]+1)%5]\n", 145 | " elif(posMap[msg[i]][1]==posMap[msg[i+1]][1]):\n", 146 | " encmsg+=keylist[(posMap[msg[i]][0]+1)%5][posMap[msg[i]][1]]\n", 147 | " encmsg+=keylist[(posMap[msg[i+1]][0]+1)%5][posMap[msg[i+1]][1]]\n", 148 | " else:\n", 149 | " encmsg+=keylist[posMap[msg[i]][0]][posMap[msg[i+1]][1]]\n", 150 | " encmsg+=keylist[posMap[msg[i+1]][0]][posMap[msg[i]][1]]\n", 151 | "print(\"Encrypted Message: \",encmsg) " 152 | ] 153 | } 154 | ], 155 | "metadata": { 156 | "kernelspec": { 157 | "display_name": "Python 3", 158 | "language": "python", 159 | "name": "python3" 160 | }, 161 | "language_info": { 162 | "codemirror_mode": { 163 | "name": "ipython", 164 | "version": 3 165 | }, 166 | "file_extension": ".py", 167 | "mimetype": "text/x-python", 168 | "name": "python", 169 | "nbconvert_exporter": "python", 170 | "pygments_lexer": "ipython3", 171 | "version": "3.7.6" 172 | } 173 | }, 174 | "nbformat": 4, 175 | "nbformat_minor": 4 176 | } 177 | -------------------------------------------------------------------------------- /Encryption_Algorithms/COMPILE.BAT: -------------------------------------------------------------------------------- 1 | bcc32 -Oi -5 -v -A -a4 -O2 -DGetCodeSize tst2fish.c twofish.c 2 | -------------------------------------------------------------------------------- /Encryption_Algorithms/DEBUG.H: -------------------------------------------------------------------------------- 1 | #ifdef DEBUG /* keep these macros common so they are same for both versions */ 2 | CONST int debugCompile = 1; 3 | extern int debug; 4 | extern void DebugIO(CONST char *s); /* display the debug output */ 5 | 6 | #define DebugDump(x,s,R,XOR,doRot,showT,needBswap) \ 7 | { if (debug) _Dump(x,s,R,XOR,doRot,showT,needBswap,t0,t1); } 8 | #define DebugDumpKey(key) { if (debug) _DumpKey(key); } 9 | #define IV_ROUND -100 10 | 11 | void _Dump(CONST void *p,CONST char *s,int R,int XOR,int doRot,int showT,int needBswap, 12 | DWORD t0,DWORD t1) 13 | { 14 | char line[512]; /* build output here */ 15 | int i,n; 16 | DWORD q[4]; 17 | 18 | if (R == IV_ROUND) 19 | sprintf(line,"%sIV: ",s); 20 | else 21 | sprintf(line,"%sR[%2d]: ",s,R); 22 | for (n=0;line[n];n++) ; 23 | 24 | for (i=0;i<4;i++) 25 | { 26 | q[i]=((CONST DWORD *)p)[i^(XOR)]; 27 | if (needBswap) q[i]=Bswap(q[i]); 28 | } 29 | 30 | sprintf(line+n,"x= %08lX %08lX %08lX %08lX.", 31 | ROR(q[0],doRot*(R )/2), 32 | ROL(q[1],doRot*(R )/2), 33 | ROR(q[2],doRot*(R+1)/2), 34 | ROL(q[3],doRot*(R+1)/2)); 35 | for (;line[n];n++) ; 36 | 37 | if (showT) 38 | sprintf(line+n," t0=%08lX. t1=%08lX.",t0,t1); 39 | for (;line[n];n++) ; 40 | 41 | sprintf(line+n,"\n"); 42 | DebugIO(line); 43 | } 44 | 45 | void _DumpKey(CONST keyInstance *key) 46 | { 47 | char line[512]; 48 | int i; 49 | int k64Cnt=(key->keyLen+63)/64; /* round up to next multiple of 64 bits */ 50 | int subkeyCnt = ROUND_SUBKEYS + 2*key->numRounds; 51 | 52 | sprintf(line,";\n;makeKey: Input key --> S-box key [%s]\n", 53 | (key->direction == DIR_ENCRYPT) ? "Encrypt" : "Decrypt"); 54 | DebugIO(line); 55 | for (i=0;i %08lX\n","", 58 | key->key32[2*i+1],key->key32[2*i],key->sboxKeys[k64Cnt-1-i]); 59 | DebugIO(line); 60 | } 61 | sprintf(line,";%11sSubkeys\n",""); 62 | DebugIO(line); 63 | for (i=0;isubKeys[2*i],key->subKeys[2*i+1], 66 | (2*i == INPUT_WHITEN) ? " Input whiten" : 67 | (2*i == OUTPUT_WHITEN) ? " Output whiten" : 68 | (2*i == ROUND_SUBKEYS) ? " Round subkeys" : ""); 69 | DebugIO(line); 70 | } 71 | DebugIO(";\n"); 72 | } 73 | #else 74 | CONST int debugCompile = 0; 75 | #define DebugDump(x,s,R,XOR,doRot,showT,needBswap) 76 | #define DebugDumpKey(key) 77 | #endif 78 | -------------------------------------------------------------------------------- /Encryption_Algorithms/MD5 Hashing.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Python code to generate MD5 hashing and check their similarity based on Hash 3 | #By Vivek Ray 4 | import hashlib # Supports hashing functions such as MD5,SHA 5 | 6 | message1= str(input("Enter message 1 =")) 7 | message2= str(input("Enter message 2 =")) 8 | 9 | encoding1 = message1.encode() 10 | encoding2 = message2.encode() 11 | 12 | hash1 = (hashlib.md5(encoding1)).hexdigest() 13 | hash2 = (hashlib.md5(encoding2)).hexdigest() 14 | 15 | # Printing the hash in hexadecimal format 16 | print("The byte equivalent of hash for message 1 is : ", hash1) 17 | 18 | # Printing the hash in hexadecimal format 19 | print("The byte equivalent of hash for message 2 is : ", hash2) 20 | 21 | if hash1 == hash2 : 22 | print("The message are similar.") 23 | else: 24 | print("The message are different.") 25 | -------------------------------------------------------------------------------- /Encryption_Algorithms/One-Time pad Encryption/README.md: -------------------------------------------------------------------------------- 1 | Language used – Python. 2 | 3 | Tkinter – This module is used to make GUIs using python language. 4 | 5 | Basics of Cryptography – Cryptography is used for Secure Communication. 6 | ``` 7 | Encryption – The process of encoding a message or information in such a way that only authorized parties can access it. 8 | Decryption – The process of taking encoded or encrypted text or other data and converting it back into text. 9 | ``` 10 | 11 | Algorithm used ONE-TIME PAD 12 | ``` 13 | The one-time pad is a type of encryption which is unbreakable. 14 | A one-time pad will generate a key, this key is shared by both the user so it does encryption as well as decryption. 15 | The key used is generated randomly and this key is combined with the plain text in order to form the ciphertext. 16 | We can use different algorithms for the generation of the ciphertext such as modular addition, modular XOR, etc. 17 | Since the key generated every time is unique, it is impossible to break. 18 | ``` -------------------------------------------------------------------------------- /Encryption_Algorithms/One-Time pad Encryption/otp.py: -------------------------------------------------------------------------------- 1 | # python module for one-timepad 2 | import onetimepad 3 | # python module to create GUI 4 | from tkinter import * 5 | 6 | root = Tk() 7 | root.title("CRYPTOGRAPHY") 8 | root.geometry("800x600") 9 | 10 | 11 | def encryptMessage(): 12 | pt = e1.get() 13 | 14 | # inbuilt function to encrypt a message 15 | ct = onetimepad.encrypt(pt, 'random') 16 | e2.insert(0, ct) 17 | 18 | 19 | def decryptMessage(): 20 | ct1 = e3.get() 21 | 22 | # inbuilt function to decrypt a message 23 | pt1 = onetimepad.decrypt(ct1, 'random') 24 | e4.insert(0, pt1) 25 | 26 | 27 | # creating labels and positioning them on the grid 28 | label1 = Label(root, text='plain text') 29 | label1.grid(row=10, column=1) 30 | label2 = Label(root, text='encrypted text') 31 | label2.grid(row=11, column=1) 32 | l3 = Label(root, text="cipher text") 33 | l3.grid(row=10, column=10) 34 | l4 = Label(root, text="decrypted text") 35 | l4.grid(row=11, column=10) 36 | 37 | # creating entries and positioning them on the grid 38 | e1 = Entry(root) 39 | e1.grid(row=10, column=2) 40 | e2 = Entry(root) 41 | e2.grid(row=11, column=2) 42 | e3 = Entry(root) 43 | e3.grid(row=10, column=11) 44 | e4 = Entry(root) 45 | e4.grid(row=11, column=11) 46 | 47 | # creating encryption button to produce the output 48 | ent = Button(root, text="encrypt", bg="red", fg="white", command=encryptMessage) 49 | ent.grid(row=13, column=2) 50 | 51 | # creating decryption button to produce the output 52 | b2 = Button(root, text="decrypt", bg="green", fg="white", command=decryptMessage) 53 | b2.grid(row=13, column=11) 54 | 55 | root.mainloop() 56 | -------------------------------------------------------------------------------- /Encryption_Algorithms/One-Time pad Encryption/requirements.txt: -------------------------------------------------------------------------------- 1 | onetimepad==1.4 -------------------------------------------------------------------------------- /Encryption_Algorithms/PLATFORM.H: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | PLATFORM.H -- Platform-specific defines for TWOFISH code 3 | 4 | Submitters: 5 | Bruce Schneier, Counterpane Systems 6 | Doug Whiting, Hi/fn 7 | John Kelsey, Counterpane Systems 8 | Chris Hall, Counterpane Systems 9 | David Wagner, UC Berkeley 10 | 11 | Code Author: Doug Whiting, Hi/fn 12 | 13 | Version 1.00 April 1998 14 | 15 | Copyright 1998, Hi/fn and Counterpane Systems. All rights reserved. 16 | 17 | Notes: 18 | * Tab size is set to 4 characters in this file 19 | 20 | ***************************************************************************/ 21 | 22 | /* use intrinsic rotate if possible */ 23 | #define ROL(x,n) (((x) << ((n) & 0x1F)) | ((x) >> (32-((n) & 0x1F)))) 24 | #define ROR(x,n) (((x) >> ((n) & 0x1F)) | ((x) << (32-((n) & 0x1F)))) 25 | 26 | #if (0) && defined(__BORLANDC__) && (__BORLANDC__ >= 0x462) 27 | #error "!!!This does not work for some reason!!!" 28 | #include /* get prototype for _lrotl() , _lrotr() */ 29 | #pragma inline __lrotl__ 30 | #pragma inline __lrotr__ 31 | #undef ROL /* get rid of inefficient definitions */ 32 | #undef ROR 33 | #define ROL(x,n) __lrotl__(x,n) /* use compiler intrinsic rotations */ 34 | #define ROR(x,n) __lrotr__(x,n) 35 | #endif 36 | 37 | #ifdef _MSC_VER 38 | #include /* get prototypes for rotation functions */ 39 | #undef ROL 40 | #undef ROR 41 | #pragma intrinsic(_lrotl,_lrotr) /* use intrinsic compiler rotations */ 42 | #define ROL(x,n) _lrotl(x,n) 43 | #define ROR(x,n) _lrotr(x,n) 44 | #endif 45 | 46 | #ifndef _M_IX86 47 | #ifdef __BORLANDC__ 48 | #define _M_IX86 300 /* make sure this is defined for Intel CPUs */ 49 | #endif 50 | #endif 51 | 52 | #ifdef _M_IX86 53 | #define LittleEndian 1 /* e.g., 1 for Pentium, 0 for 68K */ 54 | #define ALIGN32 0 /* need dword alignment? (no for Pentium) */ 55 | #else /* non-Intel platforms */ 56 | #define LittleEndian 0 /* (assume big endian */ 57 | #define ALIGN32 1 /* (assume need alignment for non-Intel) */ 58 | #endif 59 | 60 | #if LittleEndian 61 | #define Bswap(x) (x) /* NOP for little-endian machines */ 62 | #define ADDR_XOR 0 /* NOP for little-endian machines */ 63 | #else 64 | #define Bswap(x) ((ROR(x,8) & 0xFF00FF00) | (ROL(x,8) & 0x00FF00FF)) 65 | #define ADDR_XOR 3 /* convert byte address in dword */ 66 | #endif 67 | 68 | /* Macros for extracting bytes from dwords (correct for endianness) */ 69 | #define _b(x,N) (((BYTE *)&x)[((N) & 3) ^ ADDR_XOR]) /* pick bytes out of a dword */ 70 | 71 | #define b0(x) _b(x,0) /* extract LSB of DWORD */ 72 | #define b1(x) _b(x,1) 73 | #define b2(x) _b(x,2) 74 | #define b3(x) _b(x,3) /* extract MSB of DWORD */ 75 | 76 | -------------------------------------------------------------------------------- /Encryption_Algorithms/README: -------------------------------------------------------------------------------- 1 | Reference Implementation Diskette 2 | 3 | 4 | Files on this diskette (or in this ZIP file) 5 | 6 | File Name Description 7 | ======================================================================== 8 | 9 | README This file 10 | 11 | PLATFORM.H Platform-specific definitions (e.g., endianness, rotates) 12 | 13 | TABLE.H Macros and tables for Twofish internal structures 14 | 15 | AES.H AES header file, function prototypes, API explanation/example 16 | 17 | DEBUG.H Debug i/o macros and functions 18 | 19 | TWOFISH.C Reference ANSI C source code 20 | 21 | TST2FISH.C Test code, links with TWOFISH.C to generate KAT/MCT 22 | 23 | COMPILE.BAT Batch file used to compile TST2FISH.EXE. See this file for 24 | the set of compiler options used to optimize performance. 25 | 26 | TST2FISH.EXE Executable 32-bit console app of TST2FISH.C and TWOFISH.C 27 | linked together. 28 | 29 | ======================================================================== 30 | 31 | Notes: 32 | 33 | To programmers wishing to use the Twofish code: please see the 34 | example code (and comments) at the end of the file AES.H showing how 35 | the Twofish functions are typically used. 36 | 37 | The program TST2FISH.EXE will generate the full set of KAT/MCT/Tables 38 | files in the current directory, if run with the -M switch: 39 | 40 | TST2FISH -M 41 | 42 | When run without command-line parameters, it will generate a partial MCT set, 43 | since the full set takes a long time. 44 | 45 | When run with a question mark character ('?') as a parameter, TST2FISH.EXE 46 | will display a help screen of command line options. 47 | 48 | It is recommended that the version of TST2FISH.EXE compiled with the 49 | optimized ANSI C code be used to generate the full MCT file set, since 50 | the reference version is considerably slower. 51 | 52 | -------------------------------------------------------------------------------- /Encryption_Algorithms/RSA/enc_dec_RSA.cpp: -------------------------------------------------------------------------------- 1 | //C++ program for encryption and decryption 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | using namespace std; 8 | 9 | int x, y, n, t, i, flag; 10 | long int e[50], d[50], temp[50], j; 11 | char en[50], m[50]; 12 | char msg[100]; 13 | int prime(long int); //function to check for prime number 14 | void encryption_key(); 15 | long int cd(long int); 16 | void encrypt(); 17 | void decrypt(); 18 | 19 | int main() 20 | { 21 | cout << "\nENTER FIRST PRIME NUMBER\n"; 22 | cin >> x; 23 | 24 | //checking whether input is prime or not 25 | flag = prime(x); 26 | if(flag == 0) 27 | { 28 | cout << "\nINVALID INPUT\n"; 29 | exit(0); 30 | } 31 | 32 | cout << "\nENTER SECOND PRIME NUMBER\n"; 33 | cin >> y; 34 | 35 | flag = prime(y); 36 | if(flag == 0 || x == y) 37 | { 38 | cout << "\nINVALID INPUT\n"; 39 | exit(0); 40 | } 41 | 42 | cout << "\nENTER MESSAGE OR STRING TO ENCRYPT\n"; 43 | cin >> msg; 44 | 45 | for(i = 0; msg[i] != NULL; i++) 46 | m[i] = msg[i]; 47 | n = x * y; 48 | t = (x - 1) * (y - 1); 49 | 50 | encryption_key(); 51 | cout << "\nPOSSIBLE VALUES OF e AND d ARE\n"; 52 | 53 | for(i = 0; i < j - 1; i++) 54 | cout << "\n" << e[i] << "\t" << d[i]; 55 | 56 | encrypt(); 57 | decrypt(); 58 | return 0; 59 | } //end of the main program 60 | 61 | int prime(long int pr) 62 | { 63 | int i; 64 | j = sqrt(pr); 65 | for(i = 2; i <= j; i++) 66 | { 67 | if(pr % i == 0) 68 | return 0; 69 | } 70 | return 1; 71 | } 72 | 73 | //function to generate encryption key 74 | void encryption_key() 75 | { 76 | int k; 77 | k = 0; 78 | for(i = 2; i < t; i++) 79 | { 80 | if(t % i == 0) 81 | continue; 82 | flag = prime(i); 83 | if(flag == 1 && i != x && i != y) 84 | { 85 | e[k] = i; 86 | flag = cd(e[k]); 87 | if(flag > 0) 88 | { 89 | d[k] = flag; 90 | k++; 91 | } 92 | if(k == 99) 93 | break; 94 | } 95 | } 96 | } 97 | 98 | long int cd(long int a) 99 | { 100 | long int k = 1; 101 | while(1) 102 | { 103 | k = k + t; 104 | if(k % a == 0) 105 | return(k/a); 106 | } 107 | } 108 | 109 | //function to encrypt the message 110 | void encrypt() 111 | { 112 | long int pt, ct, key = e[0], k, len; 113 | i = 0; 114 | len = strlen(msg); 115 | 116 | while(i != len) 117 | { 118 | pt = m[i]; 119 | pt = pt - 96; 120 | k = 1; 121 | for(j = 0; j < key; j++) 122 | { 123 | k = k * pt; 124 | k = k % n; 125 | } 126 | temp[i] = k; 127 | ct= k + 96; 128 | en[i] = ct; 129 | i++; 130 | } 131 | en[i] = -1; 132 | cout << "\n\nTHE ENCRYPTED MESSAGE IS\n"; 133 | for(i=0; en[i] != -1; i++) 134 | cout << en[i]; 135 | } 136 | 137 | //function to decrypt the message 138 | void decrypt() 139 | { 140 | long int pt, ct, key = d[0], k; 141 | i = 0; 142 | while(en[i] != -1) 143 | { 144 | ct = temp[i]; 145 | k = 1; 146 | for(j = 0; j < key; j++) 147 | { 148 | k = k * ct; 149 | k = k % n; 150 | } 151 | pt = k + 96; 152 | m[i] = pt; 153 | i++; 154 | } 155 | m[i] = -1; 156 | cout << "\n\nTHE DECRYPTED MESSAGE IS\n"; 157 | for(i = 0; m[i] != -1; i++) 158 | cout << m[i]; 159 | 160 | cout << endl; 161 | } -------------------------------------------------------------------------------- /Encryption_Algorithms/RSA/encryption.md: -------------------------------------------------------------------------------- 1 | C++ program for strings encryption and decryption using RSA algorithm 2 | 3 | 1: Creating Keys 4 | 5 | -> Select two large prime numbers x and y 6 | -> Compute n = x * y 7 | where n is the modulus of private and the public key 8 | -> Calculate totient function, 9 | ø (n) =(x−1)(y−1) 10 | -> Choose an integer e such that e is coprime to ø(n) and 1 < e < ø(n). 11 | e is the public key exponent used for encryption 12 | ->Now choose d, so that d · e mod ø (n) = 1, i.e., >code>d is the multiplicative inverse of e in mod ø (n) 13 | 14 | 2: Encrypting Message 15 | 16 | -> Messages are encrypted using the Public key generated and is known to all. 17 | 18 | -> The public key is the function of both e and n i.e. {e,n}. 19 | 20 | -> f M is the message(plain text), then ciphertext 21 | C = M ^ n( mod n ) 22 | 23 | 3: Decrypting Message 24 | 25 | -> The private key is the function of both d and n i.e {d,n}. 26 | 27 | -> If C is the encrypted ciphertext, then the plain decrypted text M is 28 | 29 | M = C ^ d ( mod n ) -------------------------------------------------------------------------------- /Encryption_Algorithms/SHA_Hashing.py: -------------------------------------------------------------------------------- 1 | 2 | # Python 3 code to demonstrate SHA hash algorithms. 3 | 4 | import hashlib 5 | 6 | # initializing string 7 | str = "GitHub" 8 | 9 | # encoding the string passed using encode() then sending to SHA256() 10 | result = hashlib.sha256(str.encode()) 11 | 12 | # printing the equivalent hexadecimal value. 13 | print("The hexadecimal equivalent of SHA256 is : ") 14 | print(result.hexdigest()) 15 | 16 | print ("\r") 17 | 18 | # initializing string 19 | str = "GitHub" 20 | 21 | # encoding GitHub using encode() 22 | # then sending to SHA384() 23 | result = hashlib.sha384(str.encode()) 24 | 25 | # printing the equivalent hexadecimal value. 26 | print("The hexadecimal equivalent of SHA384 is : ") 27 | print(result.hexdigest()) 28 | 29 | print ("\r") 30 | 31 | # initializing string 32 | str = "GitHub" 33 | 34 | # encoding GitHub using encode() 35 | # then sending to SHA224() 36 | result = hashlib.sha224(str.encode()) 37 | 38 | # printing the equivalent hexadecimal value. 39 | print("The hexadecimal equivalent of SHA224 is : ") 40 | print(result.hexdigest()) 41 | 42 | print ("\r") 43 | 44 | # initializing string 45 | str = "GitHub" 46 | 47 | # encoding GitHub using encode() 48 | # then sending to SHA512() 49 | result = hashlib.sha512(str.encode()) 50 | 51 | # printing the equivalent hexadecimal value. 52 | print("The hexadecimal equivalent of SHA512 is : ") 53 | print(result.hexdigest()) 54 | 55 | print ("\r") 56 | 57 | # initializing string 58 | str = "GitHub" 59 | 60 | # encoding GitHub using encode() 61 | # then sending to SHA1() 62 | result = hashlib.sha1(str.encode()) 63 | 64 | # printing the equivalent hexadecimal value. 65 | print("The hexadecimal equivalent of SHA1 is : ") 66 | print(result.hexdigest()) 67 | -------------------------------------------------------------------------------- /Encryption_Algorithms/TABLE.H: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | TABLE.H -- Tables, macros, constants for Twofish S-boxes and MDS matrix 3 | 4 | Submitters: 5 | Bruce Schneier, Counterpane Systems 6 | Doug Whiting, Hi/fn 7 | John Kelsey, Counterpane Systems 8 | Chris Hall, Counterpane Systems 9 | David Wagner, UC Berkeley 10 | 11 | Code Author: Doug Whiting, Hi/fn 12 | 13 | Version 1.00 April 1998 14 | 15 | Copyright 1998, Hi/fn and Counterpane Systems. All rights reserved. 16 | 17 | Notes: 18 | * Tab size is set to 4 characters in this file 19 | * These definitions should be used in optimized and unoptimized 20 | versions to insure consistency. 21 | 22 | ***************************************************************************/ 23 | 24 | /* for computing subkeys */ 25 | #define SK_STEP 0x02020202u 26 | #define SK_BUMP 0x01010101u 27 | #define SK_ROTL 9 28 | 29 | /* Reed-Solomon code parameters: (12,8) reversible code 30 | g(x) = x**4 + (a + 1/a) x**3 + a x**2 + (a + 1/a) x + 1 31 | where a = primitive root of field generator 0x14D */ 32 | #define RS_GF_FDBK 0x14D /* field generator */ 33 | #define RS_rem(x) \ 34 | { BYTE b = (BYTE) (x >> 24); \ 35 | DWORD g2 = ((b << 1) ^ ((b & 0x80) ? RS_GF_FDBK : 0 )) & 0xFF; \ 36 | DWORD g3 = ((b >> 1) & 0x7F) ^ ((b & 1) ? RS_GF_FDBK >> 1 : 0 ) ^ g2 ; \ 37 | x = (x << 8) ^ (g3 << 24) ^ (g2 << 16) ^ (g3 << 8) ^ b; \ 38 | } 39 | 40 | /* Macros for the MDS matrix 41 | * The MDS matrix is (using primitive polynomial 169): 42 | * 01 EF 5B 5B 43 | * 5B EF EF 01 44 | * EF 5B 01 EF 45 | * EF 01 EF 5B 46 | *---------------------------------------------------------------- 47 | * More statistical properties of this matrix (from MDS.EXE output): 48 | * 49 | * Min Hamming weight (one byte difference) = 8. Max=26. Total = 1020. 50 | * Prob[8]: 7 23 42 20 52 95 88 94 121 128 91 51 | * 102 76 41 24 8 4 1 3 0 0 0 52 | * Runs[8]: 2 4 5 6 7 8 9 11 53 | * MSBs[8]: 1 4 15 8 18 38 40 43 54 | * HW= 8: 05040705 0A080E0A 14101C14 28203828 50407050 01499101 A080E0A0 55 | * HW= 9: 04050707 080A0E0E 10141C1C 20283838 40507070 80A0E0E0 C6432020 07070504 56 | * 0E0E0A08 1C1C1410 38382820 70705040 E0E0A080 202043C6 05070407 0A0E080E 57 | * 141C101C 28382038 50704070 A0E080E0 4320C620 02924B02 089A4508 58 | * Min Hamming weight (two byte difference) = 3. Max=28. Total = 390150. 59 | * Prob[3]: 7 18 55 149 270 914 2185 5761 11363 20719 32079 60 | * 43492 51612 53851 52098 42015 31117 20854 11538 6223 2492 1033 61 | * MDS OK, ROR: 6+ 7+ 8+ 9+ 10+ 11+ 12+ 13+ 14+ 15+ 16+ 62 | * 17+ 18+ 19+ 20+ 21+ 22+ 23+ 24+ 25+ 26+ 63 | */ 64 | #define MDS_GF_FDBK 0x169 /* primitive polynomial for GF(256)*/ 65 | #define LFSR1(x) ( ((x) >> 1) ^ (((x) & 0x01) ? MDS_GF_FDBK/2 : 0)) 66 | #define LFSR2(x) ( ((x) >> 2) ^ (((x) & 0x02) ? MDS_GF_FDBK/2 : 0) \ 67 | ^ (((x) & 0x01) ? MDS_GF_FDBK/4 : 0)) 68 | 69 | #define Mx_1(x) ((DWORD) (x)) /* force result to dword so << will work */ 70 | #define Mx_X(x) ((DWORD) ((x) ^ LFSR2(x))) /* 5B */ 71 | #define Mx_Y(x) ((DWORD) ((x) ^ LFSR1(x) ^ LFSR2(x))) /* EF */ 72 | 73 | #define M00 Mul_1 74 | #define M01 Mul_Y 75 | #define M02 Mul_X 76 | #define M03 Mul_X 77 | 78 | #define M10 Mul_X 79 | #define M11 Mul_Y 80 | #define M12 Mul_Y 81 | #define M13 Mul_1 82 | 83 | #define M20 Mul_Y 84 | #define M21 Mul_X 85 | #define M22 Mul_1 86 | #define M23 Mul_Y 87 | 88 | #define M30 Mul_Y 89 | #define M31 Mul_1 90 | #define M32 Mul_Y 91 | #define M33 Mul_X 92 | 93 | #define Mul_1 Mx_1 94 | #define Mul_X Mx_X 95 | #define Mul_Y Mx_Y 96 | 97 | /* Define the fixed p0/p1 permutations used in keyed S-box lookup. 98 | By changing the following constant definitions for P_ij, the S-boxes will 99 | automatically get changed in all the Twofish source code. Note that P_i0 is 100 | the "outermost" 8x8 permutation applied. See the f32() function to see 101 | how these constants are to be used. 102 | */ 103 | #define P_00 1 /* "outermost" permutation */ 104 | #define P_01 0 105 | #define P_02 0 106 | #define P_03 (P_01^1) /* "extend" to larger key sizes */ 107 | #define P_04 1 108 | 109 | #define P_10 0 110 | #define P_11 0 111 | #define P_12 1 112 | #define P_13 (P_11^1) 113 | #define P_14 0 114 | 115 | #define P_20 1 116 | #define P_21 1 117 | #define P_22 0 118 | #define P_23 (P_21^1) 119 | #define P_24 0 120 | 121 | #define P_30 0 122 | #define P_31 1 123 | #define P_32 1 124 | #define P_33 (P_31^1) 125 | #define P_34 1 126 | 127 | #define p8(N) P8x8[P_##N] /* some syntax shorthand */ 128 | 129 | /* fixed 8x8 permutation S-boxes */ 130 | 131 | /*********************************************************************** 132 | * 07:07:14 05/30/98 [4x4] TestCnt=256. keySize=128. CRC=4BD14D9E. 133 | * maxKeyed: dpMax = 18. lpMax =100. fixPt = 8. skXor = 0. skDup = 6. 134 | * log2(dpMax[ 6..18])= --- 15.42 1.33 0.89 4.05 7.98 12.05 135 | * log2(lpMax[ 7..12])= 9.32 1.01 1.16 4.23 8.02 12.45 136 | * log2(fixPt[ 0.. 8])= 1.44 1.44 2.44 4.06 6.01 8.21 11.07 14.09 17.00 137 | * log2(skXor[ 0.. 0]) 138 | * log2(skDup[ 0.. 6])= --- 2.37 0.44 3.94 8.36 13.04 17.99 139 | ***********************************************************************/ 140 | CONST BYTE P8x8[2][256]= 141 | { 142 | /* p0: */ 143 | /* dpMax = 10. lpMax = 64. cycleCnt= 1 1 1 0. */ 144 | /* 817D6F320B59ECA4.ECB81235F4A6709D.BA5E6D90C8F32471.D7F4126E9B3085CA. */ 145 | /* Karnaugh maps: 146 | * 0111 0001 0011 1010. 0001 1001 1100 1111. 1001 1110 0011 1110. 1101 0101 1111 1001. 147 | * 0101 1111 1100 0100. 1011 0101 0010 0000. 0101 1000 1100 0101. 1000 0111 0011 0010. 148 | * 0000 1001 1110 1101. 1011 1000 1010 0011. 0011 1001 0101 0000. 0100 0010 0101 1011. 149 | * 0111 0100 0001 0110. 1000 1011 1110 1001. 0011 0011 1001 1101. 1101 0101 0000 1100. 150 | */ 151 | { 152 | 0xA9, 0x67, 0xB3, 0xE8, 0x04, 0xFD, 0xA3, 0x76, 153 | 0x9A, 0x92, 0x80, 0x78, 0xE4, 0xDD, 0xD1, 0x38, 154 | 0x0D, 0xC6, 0x35, 0x98, 0x18, 0xF7, 0xEC, 0x6C, 155 | 0x43, 0x75, 0x37, 0x26, 0xFA, 0x13, 0x94, 0x48, 156 | 0xF2, 0xD0, 0x8B, 0x30, 0x84, 0x54, 0xDF, 0x23, 157 | 0x19, 0x5B, 0x3D, 0x59, 0xF3, 0xAE, 0xA2, 0x82, 158 | 0x63, 0x01, 0x83, 0x2E, 0xD9, 0x51, 0x9B, 0x7C, 159 | 0xA6, 0xEB, 0xA5, 0xBE, 0x16, 0x0C, 0xE3, 0x61, 160 | 0xC0, 0x8C, 0x3A, 0xF5, 0x73, 0x2C, 0x25, 0x0B, 161 | 0xBB, 0x4E, 0x89, 0x6B, 0x53, 0x6A, 0xB4, 0xF1, 162 | 0xE1, 0xE6, 0xBD, 0x45, 0xE2, 0xF4, 0xB6, 0x66, 163 | 0xCC, 0x95, 0x03, 0x56, 0xD4, 0x1C, 0x1E, 0xD7, 164 | 0xFB, 0xC3, 0x8E, 0xB5, 0xE9, 0xCF, 0xBF, 0xBA, 165 | 0xEA, 0x77, 0x39, 0xAF, 0x33, 0xC9, 0x62, 0x71, 166 | 0x81, 0x79, 0x09, 0xAD, 0x24, 0xCD, 0xF9, 0xD8, 167 | 0xE5, 0xC5, 0xB9, 0x4D, 0x44, 0x08, 0x86, 0xE7, 168 | 0xA1, 0x1D, 0xAA, 0xED, 0x06, 0x70, 0xB2, 0xD2, 169 | 0x41, 0x7B, 0xA0, 0x11, 0x31, 0xC2, 0x27, 0x90, 170 | 0x20, 0xF6, 0x60, 0xFF, 0x96, 0x5C, 0xB1, 0xAB, 171 | 0x9E, 0x9C, 0x52, 0x1B, 0x5F, 0x93, 0x0A, 0xEF, 172 | 0x91, 0x85, 0x49, 0xEE, 0x2D, 0x4F, 0x8F, 0x3B, 173 | 0x47, 0x87, 0x6D, 0x46, 0xD6, 0x3E, 0x69, 0x64, 174 | 0x2A, 0xCE, 0xCB, 0x2F, 0xFC, 0x97, 0x05, 0x7A, 175 | 0xAC, 0x7F, 0xD5, 0x1A, 0x4B, 0x0E, 0xA7, 0x5A, 176 | 0x28, 0x14, 0x3F, 0x29, 0x88, 0x3C, 0x4C, 0x02, 177 | 0xB8, 0xDA, 0xB0, 0x17, 0x55, 0x1F, 0x8A, 0x7D, 178 | 0x57, 0xC7, 0x8D, 0x74, 0xB7, 0xC4, 0x9F, 0x72, 179 | 0x7E, 0x15, 0x22, 0x12, 0x58, 0x07, 0x99, 0x34, 180 | 0x6E, 0x50, 0xDE, 0x68, 0x65, 0xBC, 0xDB, 0xF8, 181 | 0xC8, 0xA8, 0x2B, 0x40, 0xDC, 0xFE, 0x32, 0xA4, 182 | 0xCA, 0x10, 0x21, 0xF0, 0xD3, 0x5D, 0x0F, 0x00, 183 | 0x6F, 0x9D, 0x36, 0x42, 0x4A, 0x5E, 0xC1, 0xE0 184 | }, 185 | /* p1: */ 186 | /* dpMax = 10. lpMax = 64. cycleCnt= 2 0 0 1. */ 187 | /* 28BDF76E31940AC5.1E2B4C376DA5F908.4C75169A0ED82B3F.B951C3DE647F208A. */ 188 | /* Karnaugh maps: 189 | * 0011 1001 0010 0111. 1010 0111 0100 0110. 0011 0001 1111 0100. 1111 1000 0001 1100. 190 | * 1100 1111 1111 1010. 0011 0011 1110 0100. 1001 0110 0100 0011. 0101 0110 1011 1011. 191 | * 0010 0100 0011 0101. 1100 1000 1000 1110. 0111 1111 0010 0110. 0000 1010 0000 0011. 192 | * 1101 1000 0010 0001. 0110 1001 1110 0101. 0001 0100 0101 0111. 0011 1011 1111 0010. 193 | */ 194 | { 195 | 0x75, 0xF3, 0xC6, 0xF4, 0xDB, 0x7B, 0xFB, 0xC8, 196 | 0x4A, 0xD3, 0xE6, 0x6B, 0x45, 0x7D, 0xE8, 0x4B, 197 | 0xD6, 0x32, 0xD8, 0xFD, 0x37, 0x71, 0xF1, 0xE1, 198 | 0x30, 0x0F, 0xF8, 0x1B, 0x87, 0xFA, 0x06, 0x3F, 199 | 0x5E, 0xBA, 0xAE, 0x5B, 0x8A, 0x00, 0xBC, 0x9D, 200 | 0x6D, 0xC1, 0xB1, 0x0E, 0x80, 0x5D, 0xD2, 0xD5, 201 | 0xA0, 0x84, 0x07, 0x14, 0xB5, 0x90, 0x2C, 0xA3, 202 | 0xB2, 0x73, 0x4C, 0x54, 0x92, 0x74, 0x36, 0x51, 203 | 0x38, 0xB0, 0xBD, 0x5A, 0xFC, 0x60, 0x62, 0x96, 204 | 0x6C, 0x42, 0xF7, 0x10, 0x7C, 0x28, 0x27, 0x8C, 205 | 0x13, 0x95, 0x9C, 0xC7, 0x24, 0x46, 0x3B, 0x70, 206 | 0xCA, 0xE3, 0x85, 0xCB, 0x11, 0xD0, 0x93, 0xB8, 207 | 0xA6, 0x83, 0x20, 0xFF, 0x9F, 0x77, 0xC3, 0xCC, 208 | 0x03, 0x6F, 0x08, 0xBF, 0x40, 0xE7, 0x2B, 0xE2, 209 | 0x79, 0x0C, 0xAA, 0x82, 0x41, 0x3A, 0xEA, 0xB9, 210 | 0xE4, 0x9A, 0xA4, 0x97, 0x7E, 0xDA, 0x7A, 0x17, 211 | 0x66, 0x94, 0xA1, 0x1D, 0x3D, 0xF0, 0xDE, 0xB3, 212 | 0x0B, 0x72, 0xA7, 0x1C, 0xEF, 0xD1, 0x53, 0x3E, 213 | 0x8F, 0x33, 0x26, 0x5F, 0xEC, 0x76, 0x2A, 0x49, 214 | 0x81, 0x88, 0xEE, 0x21, 0xC4, 0x1A, 0xEB, 0xD9, 215 | 0xC5, 0x39, 0x99, 0xCD, 0xAD, 0x31, 0x8B, 0x01, 216 | 0x18, 0x23, 0xDD, 0x1F, 0x4E, 0x2D, 0xF9, 0x48, 217 | 0x4F, 0xF2, 0x65, 0x8E, 0x78, 0x5C, 0x58, 0x19, 218 | 0x8D, 0xE5, 0x98, 0x57, 0x67, 0x7F, 0x05, 0x64, 219 | 0xAF, 0x63, 0xB6, 0xFE, 0xF5, 0xB7, 0x3C, 0xA5, 220 | 0xCE, 0xE9, 0x68, 0x44, 0xE0, 0x4D, 0x43, 0x69, 221 | 0x29, 0x2E, 0xAC, 0x15, 0x59, 0xA8, 0x0A, 0x9E, 222 | 0x6E, 0x47, 0xDF, 0x34, 0x35, 0x6A, 0xCF, 0xDC, 223 | 0x22, 0xC9, 0xC0, 0x9B, 0x89, 0xD4, 0xED, 0xAB, 224 | 0x12, 0xA2, 0x0D, 0x52, 0xBB, 0x02, 0x2F, 0xA9, 225 | 0xD7, 0x61, 0x1E, 0xB4, 0x50, 0x04, 0xF6, 0xC2, 226 | 0x16, 0x25, 0x86, 0x56, 0x55, 0x09, 0xBE, 0x91 227 | } 228 | }; 229 | -------------------------------------------------------------------------------- /Encryption_Algorithms/TST2FISH.C: -------------------------------------------------------------------------------- 1 | /*************************************************************************** 2 | TST2FISH.C -- Test code for Twofish encryption 3 | 4 | Submitters: 5 | Bruce Schneier, Counterpane Systems 6 | Doug Whiting, Hi/fn 7 | John Kelsey, Counterpane Systems 8 | Chris Hall, Counterpane Systems 9 | David Wagner, UC Berkeley 10 | 11 | Code Author: Doug Whiting, Hi/fn 12 | 13 | Version 1.00 April 1998 14 | 15 | Copyright 1998, Hi/fn and Counterpane Systems. All rights reserved. 16 | 17 | Notes: 18 | * Tab size is set to 4 characters in this file 19 | * A random number generator is generated and used here, so that 20 | the same results can be generated on different platforms/compilers. 21 | * Command line arguments: 22 | -h or ? ==> give help message 23 | -lNN ==> set sanity count test loop count to NN 24 | -m ==> do full MCT generation 25 | -pPath ==> set file base path 26 | -r ==> set initial random seed based on time 27 | -tNN ==> perform timings with iteration count NN 28 | -rNN ==> set initial random seed to NN 29 | -v ==> read & verify files instead of creating them 30 | 31 | ***************************************************************************/ 32 | 33 | #include "aes.h" 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | 40 | extern CONST char *moduleDescription; /* which module is running */ 41 | extern CONST char *modeString; /* which key schedule mode */ 42 | extern CONST int debugCompile; /* is external module compiled with debug? */ 43 | 44 | char CompilerName[8]= 45 | #if defined(__BORLANDC__) 46 | "BCC"; 47 | #elif defined(_MSC_VER) 48 | "MSC"; 49 | #elif defined(__WATCOMC__) 50 | "WAT"; 51 | #else 52 | "???"; 53 | #endif 54 | 55 | #if defined(__WATCOMC__) && defined(_M_IX86) && !defined(NO_TIMER) 56 | DWORD ReadTimeStampCounter(void); 57 | #pragma aux ReadTimeStampCounter = " db 0Fh,031h" value [eax] modify exact [eax edx] // RDTSC opcode 58 | #endif 59 | 60 | 61 | /* 62 | +***************************************************************************** 63 | * Constants/Macros/Tables 64 | -****************************************************************************/ 65 | 66 | typedef struct 67 | { 68 | FILE *f; /* the file being written/read */ 69 | int I; /* test number */ 70 | int keySize; /* key size in bits */ 71 | int gotDebugIO; /* got any debug IO? */ 72 | BYTE pt[BLOCK_SIZE/8]; /* plaintext */ 73 | BYTE ct[BLOCK_SIZE/8]; /* ciphertext */ 74 | 75 | keyInstance ki; /* use ki.keyDwords as key bits */ 76 | cipherInstance ci; /* use ci.iv as iv bits */ 77 | } testData; 78 | 79 | 80 | static char hexTab[] = "0123456789ABCDEF"; 81 | char filePath[80]= ""; 82 | 83 | int useAsm = 0; /* use assembly language */ 84 | int mctInner = MCT_INNER/100; 85 | int mctOuter = MCT_OUTER/10; 86 | int verify = 0; /* set to nonzero to read&verify files */ 87 | int debug = 0; /* debugging mode */ 88 | int verbose = 0; /* verbose output */ 89 | int quietVerify = 0; /* quiet during verify */ 90 | int timeIterCnt = 0; /* how many times to iterate for timing */ 91 | DWORD randBits[64]= {1}; /* use Knuth's additive generator */ 92 | int randPtr; 93 | testData * debugTD = NULL; /* for use with debugIO */ 94 | int CLKS_BYTE = 0; /* use clks/byte? (vs. clks/block) */ 95 | int FMT_LOG = 0; /* format for log file */ 96 | int CLK_MHZ = 200;/* default clock speed */ 97 | 98 | #define KEY_BITS_0 128 /* first key bit setting to test */ 99 | #define STEP_KEY_BITS ((MAX_KEY_BITS-KEY_BITS_0)/2) 100 | 101 | static char hexString[]= 102 | "0123456789ABCDEFFEDCBA987654321000112233445566778899AABBCCDDEEFF"; 103 | 104 | /* 105 | +***************************************************************************** 106 | * Functions 107 | -****************************************************************************/ 108 | DWORD Here(DWORD x) 109 | { 110 | unsigned int mask=~0U; 111 | 112 | return (* (((DWORD *)&x)-1)) & mask; 113 | } 114 | extern DWORD TwofishCodeSize(void); 115 | 116 | #ifdef USE_ASM 117 | int cdecl get_cpu_type(void); /* return CPU type */ 118 | #endif 119 | 120 | /* 121 | +***************************************************************************** 122 | * 123 | * Function Name: Rand 124 | * 125 | * Function: Generate random number 126 | * 127 | * Arguments: None. 128 | * 129 | * Return: New random number. 130 | * 131 | * Notes: Uses Knuth's additive generator, other magic 132 | * 133 | -****************************************************************************/ 134 | DWORD Rand(void) 135 | { 136 | if (randPtr >= 57) 137 | randPtr = 0; /* handle the ptr wrap */ 138 | 139 | randBits[randPtr] += randBits[(randPtr < 7) ? randPtr-7+57 : randPtr-7]; 140 | 141 | randBits[62]+= randBits[61]; 142 | randBits[63] = ROL(randBits[63],9) + 0x6F4ED7D0; /* very long period! */ 143 | 144 | return (randBits[randPtr++] ^ randBits[63]) + randBits[62]; 145 | } 146 | 147 | 148 | /* 149 | +***************************************************************************** 150 | * 151 | * Function Name: SetRand 152 | * 153 | * Function: Initialize random number seed 154 | * 155 | * Arguments: seed = new seed value 156 | * 157 | * Return: None. 158 | * 159 | * Notes: 160 | * 161 | -****************************************************************************/ 162 | void SetRand(DWORD seed) 163 | { 164 | int i; 165 | DWORD x; 166 | 167 | randPtr=0; 168 | for (i=x=0;i<64;i++) 169 | { 170 | randBits[i]=seed; 171 | x |= seed; /* keep track of lsb of all entries */ 172 | seed = ROL(seed,11) + 0x12345678; 173 | } 174 | 175 | if ((x & 1) == 0) /* insure maximal period by having at least one odd value */ 176 | randBits[0]++; 177 | 178 | for (i=0;i<1000;i++) 179 | Rand(); /* run it for a while */ 180 | 181 | randBits[63] = Rand(); 182 | randBits[62] = Rand(); 183 | randBits[61] = Rand() | 1; /* make it odd */ 184 | } 185 | 186 | 187 | /* 188 | +***************************************************************************** 189 | * 190 | * Function Name: ClearTestData 191 | * 192 | * Function: Initialize test data to all zeroes 193 | * 194 | * Arguments: t = pointer to testData structure 195 | * 196 | * Return: None. 197 | * 198 | * Notes: 199 | * 200 | -****************************************************************************/ 201 | void ClearTestData(testData *t) 202 | { 203 | t->gotDebugIO=0; 204 | memset(t->pt,0,BLOCK_SIZE/8); 205 | memset(t->ct,0,BLOCK_SIZE/8); 206 | memset(t->ci.iv32,0,BLOCK_SIZE/8); 207 | memset(t->ki.key32,0,MAX_KEY_BITS/8); 208 | memset(t->ki.keyMaterial,'0',sizeof(t->ki.keyMaterial)); 209 | #if defined(COMPILE_KEY) && defined(USE_ASM) 210 | t->ki.cSig1=t->ki.cSig2=0; 211 | #endif 212 | } 213 | 214 | /* 215 | +***************************************************************************** 216 | * 217 | * Function Name: FatalError 218 | * 219 | * Function: Output a fatal error message and exit 220 | * 221 | * Arguments: msg = fatal error description (printf string) 222 | * msg2 = 2nd parameter to printf msg 223 | * 224 | * Return: None. 225 | * 226 | * Notes: 227 | * 228 | -****************************************************************************/ 229 | void FatalError(CONST char *msg,CONST char *msg2) 230 | { 231 | printf("\nFATAL ERROR: "); 232 | printf(msg,msg2); 233 | exit(2); 234 | } 235 | 236 | 237 | /* 238 | +***************************************************************************** 239 | * 240 | * Function Name: GetTimer 241 | * 242 | * Function: Return a hi-frequency timer value 243 | * 244 | * Arguments: None 245 | * 246 | * Return: None. 247 | * 248 | * Notes: 249 | * 250 | -****************************************************************************/ 251 | DWORD GetTimer(void) 252 | { 253 | DWORD x; 254 | 255 | #if defined(__BORLANDC__) && defined(__WIN32__) && !defined(NO_TIMER) 256 | #define HI_RES_CLK 1 257 | x=0; 258 | #pragma option -Od /* disable optimizations (it's a REAL hack!) */ 259 | __emit__(0x0F); __emit__(0x31); /* RDTSC opcode */ 260 | #pragma option -O. /* restore optimization setting */ 261 | #elif defined(_MSC_VER) && defined(_M_IX86) && !defined(NO_TIMER) 262 | #define HI_RES_CLK 1 263 | _asm 264 | { 265 | _emit 0x0F 266 | _emit 0x31 267 | mov x,eax 268 | }; 269 | #elif defined(__WATCOMC__) && defined(_M_IX86) && !defined(NO_TIMER) 270 | #define HI_RES_CLK 1 271 | x = ReadTimeStampCounter(); 272 | #elif defined(CLOCKS_PER_SEC) 273 | x=clock(); 274 | #else 275 | #define CLOCKS_PER_SEC 1 /* very low resolution timer */ 276 | x=time(NULL); 277 | #endif 278 | 279 | return x; 280 | } 281 | 282 | 283 | /* 284 | +***************************************************************************** 285 | * 286 | * Function Name: TimeOps 287 | * 288 | * Function: Time encryption/decryption and print results 289 | * 290 | * Arguments: iterCnt = how many calls to make 291 | * 292 | * Return: None. 293 | * 294 | * Notes: None. 295 | * 296 | -****************************************************************************/ 297 | void TimeOps(int iterCnt) 298 | { 299 | enum { TEST_CNT = 3, BLOCK_CNT=64 }; 300 | int i,j,k,n,q; 301 | DWORD t0,t1,dt[8],minT; 302 | DWORD testTime[3][TEST_CNT]; 303 | testData t; 304 | BYTE text[BLOCK_CNT*(BLOCK_SIZE/8)]; 305 | static char *testName[TEST_CNT]={"BlockEncrypt:","BlockDecrypt:","reKeyEncrypt:"}; 306 | static char *atomName[TEST_CNT]={"block","block","call "}; 307 | static char *format [TEST_CNT]={"%10.1f/%s ","%10.1f/%s ","%10.1f/%s "}; 308 | static int denom [TEST_CNT]={BLOCK_CNT,BLOCK_CNT,1}; 309 | static int needSet [TEST_CNT]={1,1,0}; 310 | 311 | ClearTestData(&t); 312 | for (i=0;i t1-t0) 387 | minT = t1-t0; 388 | } 389 | testTime[q][n]=minT; 390 | } 391 | } 392 | /* now print all the results */ 393 | #ifdef HI_RES_CLK 394 | if (!FMT_LOG) 395 | { 396 | printf("\nCalibrate GetTimer(): ",t1-t0); 397 | for (i=0;i> (8*(q&3))); /* auto-Bswap! */ 521 | for (j=0;j= debug) 556 | exit(1); 557 | printf(";-------------------------------------------------\n"); 558 | } 559 | } 560 | } 561 | } 562 | debug=saveDebug; 563 | if (!quietVerify) printf(" OK\n"); 564 | } 565 | 566 | 567 | /* 568 | +***************************************************************************** 569 | * 570 | * Function Name: AES_FileIO 571 | * 572 | * Function: Output to file or verify file contents vs. string 573 | * 574 | * Arguments: f = opened file 575 | * s = string to output/compare (NULL-->reset, return) 576 | * errOK = do not fatalError on miscompare 577 | * 578 | * Return: Zero --> compare ok 579 | * 580 | * Notes: On miscompare, FatalError (unless errOK) 581 | * 582 | -****************************************************************************/ 583 | int AES_FileIO(FILE *f,CONST char *s,int errOK) 584 | { 585 | int i; 586 | static int lineNum=0; 587 | static int j=0; 588 | static char line[516]=""; 589 | 590 | if (s == NULL) /* starting new file */ 591 | { 592 | line[0]=j=lineNum=0; 593 | return 0; 594 | } 595 | 596 | if (!verify) 597 | { 598 | fprintf(f,s); 599 | return 0; 600 | } 601 | 602 | /* here to verify the file against the string */ 603 | for (i=0;s[i];i++) 604 | { 605 | while (line[j] == 0) 606 | { 607 | lineNum++; 608 | if (fgets(line,sizeof(line)-4,f) == NULL) 609 | { 610 | if ((s[i]=='\n') && (s[i+1]==0)) 611 | { 612 | line[0]=j=0; /* missing final eol is ok */ 613 | return 0; 614 | } 615 | FatalError("Unexpected EOF looking for %s",s); 616 | } 617 | if (verbose) printf(line); 618 | j=0; 619 | } 620 | if (s[i] != line[j]) 621 | { 622 | if ((s[i] == '\n') && ((i==0) || (s[i-1] == '\n'))) continue; /* blank line skip */ 623 | if (line[j] == '\n') {j++; continue; } 624 | if (!errOK) 625 | { 626 | char tmp[1024]; 627 | sprintf(tmp,"Miscompare at line #%d:\n%s\nlooking for\n\n%%s",lineNum,line); 628 | FatalError(tmp,s); 629 | } 630 | line[0]=j=0; /* let caller re-synch if desired */ 631 | return 1; /* return error flag */ 632 | } 633 | j++; 634 | } 635 | 636 | return 0; 637 | } 638 | 639 | 640 | 641 | /* 642 | +***************************************************************************** 643 | * 644 | * Function Name: AES_PutFileHeader 645 | * 646 | * Function: Output a text header for AES test file 647 | * 648 | * Arguments: fileName = name of file to create 649 | * testName = name of the specific test 650 | * 651 | * Return: Open FILE pointer 652 | * 653 | * Notes: If unable to create, gives FatalError 654 | * 655 | -****************************************************************************/ 656 | FILE *AES_PutFileHeader(CONST char *fileName,CONST char *testName) 657 | { 658 | char s[512]; 659 | FILE *f; 660 | 661 | sprintf(s,"%s%s",filePath,fileName); 662 | if (verify) 663 | { 664 | if (!quietVerify) printf("Verifying file %s",s); 665 | f=fopen(s,"rt"); 666 | AES_FileIO(NULL,NULL,0); /* reset file read state */ 667 | } 668 | else 669 | { 670 | printf("Creating file %s.\n",s); 671 | f=fopen(s,"wt"); 672 | } 673 | if (f == NULL) FatalError("Unable to open file '%s'",s); 674 | 675 | sprintf(s, 676 | "\n=========================\n" 677 | "\n" 678 | "FILENAME: \"%s\"\n" 679 | "\n" 680 | "%s\n" 681 | "\n" 682 | "Algorithm Name: TWOFISH\n" 683 | "Principal Submitter: Bruce Schneier, Counterpane Systems\n" 684 | "\n" 685 | "==========\n" 686 | "\n", 687 | fileName,testName); 688 | 689 | if (AES_FileIO(f,s,1)) 690 | { /* header mismatch */ 691 | if (!verify) 692 | FatalError("Miscompare while not verifying??",""); 693 | printf(" \tWARNING: header mismatch!"); 694 | fgets(s,sizeof(s)-4,f); 695 | do { /* skip rest of "bad" header */ 696 | if (fgets(s,sizeof(s)-4,f) == NULL) 697 | break; /* end of file? */ 698 | } 699 | while ((s[0] != '=') || (s[1] != '=')); 700 | fgets(s,sizeof(s)-4,f); /* skip trailing blank line */ 701 | } 702 | 703 | if (verify) 704 | if (!quietVerify) printf("\n"); 705 | 706 | return f; 707 | } 708 | 709 | /* 710 | +***************************************************************************** 711 | * 712 | * Function Name: AES_PutTestResult 713 | * 714 | * Function: Output a test result 715 | * 716 | * Arguments: f = output file 717 | * name = name of field 718 | * p = pointer to bytes/dwords 719 | * cnt = # bytes to output 720 | * fmt32 = nonzero --> p points to dwords, else bytes 721 | * Return: None. 722 | * 723 | * Notes: 724 | * 725 | -****************************************************************************/ 726 | void AES_PutBytes(FILE *f,CONST char *name,CONST void *p,int cnt,int fmt32) 727 | { 728 | char s[128]; 729 | int i,j,a; 730 | if (p == NULL) return; 731 | 732 | a = (fmt32) ? ADDR_XOR : 0; /* handle big/little endian on dword i/o */ 733 | 734 | sprintf(s,"%s=",name); 735 | for (j=0;s[j];j++) ; 736 | for (i=0;i> 4 ]; 739 | s[j++]=hexTab[((BYTE *)p)[i ^ a] & 0xF]; 740 | } 741 | s[j++]='\n'; 742 | s[j ]=0; /* terminate the string */ 743 | 744 | AES_FileIO(f,s,0); 745 | } 746 | 747 | 748 | /* 749 | +***************************************************************************** 750 | * 751 | * Function Name: AES_printf 752 | * 753 | * Function: Output a test result 754 | * 755 | * Arguments: t = testData (includes output file) 756 | * fmt = format list (string of chars, see notes) 757 | * 758 | * Return: None. 759 | * 760 | * Notes: 761 | * The fmt string specifies what is output. The following characters are 762 | * treated specially (S,K,P,C,v,V,I). See the code in the switch statement 763 | * to see how they are handled. All other characters (e.g., '\n') are 764 | * simply output to the file. 765 | * 766 | -****************************************************************************/ 767 | void AES_printf(testData *t,CONST char *fmt) 768 | { 769 | char s[40]; 770 | 771 | for (s[1]=0;*fmt;fmt++) 772 | switch (*fmt) 773 | { 774 | case 'I': sprintf(s,"I=%d\n",t->I); AES_FileIO(t->f,s,0); break; 775 | case 'S': sprintf(s,"KEYSIZE=%d\n",t->keySize); AES_FileIO(t->f,s,0); break; 776 | case 'P': AES_PutBytes(t->f,"PT" ,t->pt ,BLOCK_SIZE/8,0); break; 777 | case 'C': AES_PutBytes(t->f,"CT" ,t->ct ,BLOCK_SIZE/8,0); break; 778 | case 'v': AES_PutBytes(t->f,"IV" ,t->ci.IV ,BLOCK_SIZE/8,0); break; 779 | case 'V': AES_PutBytes(t->f,"IV" ,t->ci.iv32 ,BLOCK_SIZE/8,1); break; 780 | case 'K': AES_PutBytes(t->f,"KEY",t->ki.key32,t->keySize/8,1); break; 781 | default: s[0]=*fmt; s[1]=0; AES_FileIO(t->f,s,0); break; 782 | } 783 | } 784 | 785 | /* 786 | +***************************************************************************** 787 | * 788 | * Function Name: AES_EndSection 789 | * 790 | * Function: Insert a separator between sections 791 | * 792 | * Arguments: t = ptr to testData, contains file 793 | * 794 | * Return: None. 795 | * 796 | * Notes: 797 | * 798 | -****************************************************************************/ 799 | void AES_EndSection(testData *t) 800 | { 801 | AES_FileIO(t->f,"==========\n\n",0); 802 | } 803 | 804 | /* 805 | +***************************************************************************** 806 | * 807 | * Function Name: AES_Close 808 | * 809 | * Function: Close an AES text file 810 | * 811 | * Arguments: t = testData ptr (contains f) 812 | * 813 | * Return: None. 814 | * 815 | * Notes: 816 | * 817 | -****************************************************************************/ 818 | void AES_Close(testData *t) 819 | { 820 | fclose(t->f); 821 | } 822 | 823 | /* 824 | +***************************************************************************** 825 | * 826 | * Function Name: DebugIO 827 | * 828 | * Function: Output debug string 829 | * 830 | * Arguments: s = string to output 831 | * 832 | * Return: None. 833 | * 834 | * Notes: 835 | * 836 | -****************************************************************************/ 837 | void DebugIO(CONST char *s) 838 | { 839 | if (debugTD) 840 | { 841 | AES_FileIO(debugTD->f,s,0); 842 | debugTD->gotDebugIO=1; 843 | } 844 | else 845 | printf(s); 846 | } 847 | 848 | /* 849 | +***************************************************************************** 850 | * 851 | * Function Name: AES_Test_VK 852 | * 853 | * Function: Run variable key test 854 | * 855 | * Arguments: fname = file name to produce 856 | * 857 | * Return: None. 858 | * 859 | * Notes: 860 | * 861 | -****************************************************************************/ 862 | void AES_Test_VK(CONST char *fname) 863 | { 864 | testData t; 865 | 866 | memset(t.ki.keyMaterial,'0',MAX_KEY_SIZE); 867 | 868 | t.f=AES_PutFileHeader(fname, 869 | "Electronic Codebook (ECB) Mode\nVariable Key Known Answer Tests"); 870 | 871 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 872 | FatalError("cipherInit error during %s test",fname); 873 | 874 | for (t.keySize=KEY_BITS_0;t.keySize<=MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS) 875 | { 876 | ClearTestData(&t); 877 | AES_printf(&t,"S\nP\n"); /* output key size, plaintext */ 878 | for (t.I=1;t.I<=t.keySize;t.I++) 879 | { 880 | t.ki.keyMaterial[(t.I-1)/4]='0' + (8 >> ((t.I-1) & 3)); 881 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 882 | FatalError("Error parsing key during %s test",fname); 883 | if (blockEncrypt(&t.ci,&t.ki,t.pt,BLOCK_SIZE,t.ct) != BLOCK_SIZE) 884 | FatalError("blockEncrypt return during %s test",fname); 885 | AES_printf(&t,"IKC\n"); /* output I, KEY, CT, newline */ 886 | 887 | t.ki.keyMaterial[(t.I-1)/4]='0'; /* rezero the key bit */ 888 | } 889 | AES_EndSection(&t); 890 | } 891 | 892 | AES_Close(&t); 893 | } 894 | 895 | /* 896 | +***************************************************************************** 897 | * 898 | * Function Name: AES_Test_Intermediate 899 | * 900 | * Function: Run intermediate value test 901 | * 902 | * Arguments: fname = file name to produce 903 | * 904 | * Return: None. 905 | * 906 | * Notes: 907 | * 908 | -****************************************************************************/ 909 | void AES_Test_Intermediate(CONST char *fname) 910 | { 911 | testData t; 912 | 913 | if ((useAsm) || (!debugCompile)) 914 | { 915 | if (!quietVerify) printf("WARNING: Skipping %s test\n",fname); 916 | return; 917 | } 918 | 919 | memset(t.ki.keyMaterial,'0',MAX_KEY_SIZE); 920 | 921 | t.f=AES_PutFileHeader(fname, 922 | "Electronic Codebook (ECB) Mode\nIntermediate Value Tests"); 923 | 924 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 925 | FatalError("cipherInit error during %s test",fname); 926 | 927 | for (t.keySize=KEY_BITS_0;t.keySize<=MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS) 928 | { 929 | ClearTestData(&t); 930 | debugTD=&t; 931 | debug=1; 932 | 933 | if (t.keySize > KEY_BITS_0) 934 | memcpy(t.ki.keyMaterial,hexString,sizeof(t.ki.keyMaterial)); 935 | debug=0; 936 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 937 | FatalError("Error parsing key during %s test",fname); 938 | debug=1; 939 | AES_printf(&t,"S\nK\n"); /* output key size, key */ 940 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 941 | FatalError("Error parsing key during %s test",fname); 942 | 943 | AES_printf(&t,"P\n"); /* output plaintext */ 944 | AES_FileIO(t.f,"Encrypt()\n",0); 945 | 946 | if (blockEncrypt(&t.ci,&t.ki,t.pt,BLOCK_SIZE,t.ct) != BLOCK_SIZE) 947 | FatalError("blockEncrypt return during %s test",fname); 948 | AES_printf(&t,"\nC\n"); /* output CT, newline */ 949 | 950 | AES_FileIO(t.f,"Decrypt()\n",0); 951 | AES_printf(&t,"\nC\n"); /* output CT, newline */ 952 | if (blockDecrypt(&t.ci,&t.ki,t.ct,BLOCK_SIZE,t.pt) != BLOCK_SIZE) 953 | FatalError("blockDecrypt return during %s test",fname); 954 | AES_printf(&t,"\nP\n"); /* output PT, newline */ 955 | 956 | AES_EndSection(&t); 957 | if (!t.gotDebugIO) 958 | FatalError("Need to run DEBUG version to test %s",fname); 959 | debug=0; 960 | debugTD=NULL; 961 | } 962 | 963 | AES_Close(&t); 964 | } 965 | 966 | 967 | /* 968 | +***************************************************************************** 969 | * 970 | * Function Name: AES_Test_VT 971 | * 972 | * Function: Run variable text test 973 | * 974 | * Arguments: fname = file name to produce 975 | * 976 | * Return: None. 977 | * 978 | * Notes: 979 | * 980 | -****************************************************************************/ 981 | void AES_Test_VT(CONST char *fname) 982 | { 983 | testData t; 984 | 985 | memset( t.ki.keyMaterial,'0',MAX_KEY_SIZE); 986 | 987 | t.f=AES_PutFileHeader(fname, 988 | "Electronic Codebook (ECB) Mode\nVariable Text Known Answer Tests"); 989 | 990 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 991 | FatalError("cipherInit error during %s test",fname); 992 | 993 | for (t.keySize=KEY_BITS_0;t.keySize<=MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS) 994 | { 995 | ClearTestData(&t); 996 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 997 | FatalError("Error parsing key during %s test",fname); 998 | 999 | AES_printf(&t,"S\nK\n"); /* output key size, key */ 1000 | for (t.I=1;t.I<=BLOCK_SIZE;t.I++) 1001 | { 1002 | t.pt[(t.I-1)/8] = 0x80 >> ((t.I-1) & 7); 1003 | if (blockEncrypt(&t.ci,&t.ki,t.pt,BLOCK_SIZE,t.ct) != BLOCK_SIZE) 1004 | FatalError("blockEncrypt return during %s test",fname); 1005 | AES_printf(&t,"IPC\n"); /* output I, PT, CT, newline */ 1006 | t.pt[(t.I-1)/8] = 0; 1007 | } 1008 | AES_EndSection(&t); 1009 | } 1010 | AES_Close(&t); 1011 | } 1012 | 1013 | /* 1014 | +***************************************************************************** 1015 | * 1016 | * Function Name: AES_Test_TBL 1017 | * 1018 | * Function: Run tabl test 1019 | * 1020 | * Arguments: fname = file name to produce 1021 | * 1022 | * Return: None. 1023 | * 1024 | * Notes: 1025 | * 1026 | -****************************************************************************/ 1027 | void AES_Test_TBL(CONST char *fname) 1028 | { 1029 | int i; 1030 | testData t; 1031 | 1032 | t.f=AES_PutFileHeader(fname, 1033 | "Electronic Codebook (ECB) Mode\nTables Known Answer Test\n" 1034 | "Tests permutation tables and MDS matrix multiply tables."); 1035 | 1036 | for (t.keySize=KEY_BITS_0;t.keySize <= MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS) 1037 | { 1038 | AES_printf(&t,"S\n"); /* output key size */ 1039 | TableOp(TAB_ENABLE); 1040 | TableOp(TAB_RESET); 1041 | 1042 | ClearTestData(&t); 1043 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 1044 | FatalError("Error cipherInit() during %s test",fname); 1045 | 1046 | for (t.I=1;TableOp(TAB_QUERY) == FALSE;t.I++) 1047 | { 1048 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 1049 | FatalError("Error parsing key during %s test",fname); 1050 | if (blockEncrypt(&t.ci,&t.ki,t.pt,BLOCK_SIZE,t.ct) != BLOCK_SIZE) 1051 | FatalError("blockEncrypt during %s test",fname); 1052 | AES_printf(&t,"IKPC\n"); /* show the 'vector' */ 1053 | memcpy(t.ki.keyMaterial+MAX_KEY_SIZE/2,t.ki.keyMaterial,MAX_KEY_SIZE/2); 1054 | for (i=0;i> 4]; 1057 | t.ki.keyMaterial[i+1]=hexTab[t.pt[i/2] &0xF]; 1058 | } 1059 | memcpy(t.pt,t.ct,BLOCK_SIZE/8); /* use ciphertext as new plaintext */ 1060 | } 1061 | TableOp(TAB_DISABLE); 1062 | AES_EndSection(&t); /* output separator */ 1063 | if (!quietVerify) printf(" [%d,%3d]",t.keySize,t.I); 1064 | } 1065 | if (!quietVerify) printf("\n"); 1066 | AES_Close(&t); 1067 | } 1068 | 1069 | /* 1070 | +***************************************************************************** 1071 | * 1072 | * Function Name: AES_Test_ECB_E_MCT 1073 | * 1074 | * Function: Run ECB Monte Carlo test for ECB encryption 1075 | * 1076 | * Arguments: fname = file name to produce 1077 | * 1078 | * Return: None. 1079 | * 1080 | * Notes: 1081 | * 1082 | -****************************************************************************/ 1083 | void AES_Test_ECB_E_MCT(CONST char *fname) 1084 | { 1085 | int i,j,q; 1086 | testData t; 1087 | 1088 | t.f=AES_PutFileHeader(fname, 1089 | "Electronic Codebook (ECB) Mode - ENCRYPTION\nMonte Carlo Test"); 1090 | 1091 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 1092 | FatalError("cipherInit error during %s test",fname); 1093 | 1094 | for (t.keySize=KEY_BITS_0,q=0;t.keySize<=MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS,q+=2) 1095 | { 1096 | AES_printf(&t,"S\n"); /* output key size */ 1097 | if (!quietVerify) printf(" keyLen = %3d. ",t.keySize); 1098 | 1099 | ClearTestData(&t); /* start with all zeroes */ 1100 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 1101 | FatalError("Error parsing key during %s test",fname); 1102 | 1103 | for (t.I=0;t.I=q) ? ((DWORD *)t.ct)[i-q] : 1115 | ((DWORD *)t.pt)[BLOCK_SIZE/32-q+i]); 1116 | BlockCopy(t.pt,t.ct); 1117 | } 1118 | AES_printf(&t,"C\n"); 1119 | if (reKey(&t.ki) != TRUE) 1120 | FatalError("reKey return during %s test",fname); 1121 | } 1122 | AES_EndSection(&t); 1123 | } 1124 | if (!quietVerify) printf(" \n"); 1125 | AES_Close(&t); 1126 | } 1127 | 1128 | /* 1129 | +***************************************************************************** 1130 | * 1131 | * Function Name: AES_Test_ECB_D_MCT 1132 | * 1133 | * Function: Run ECB Monte Carlo test for ECB decryption 1134 | * 1135 | * Arguments: fname = file name to produce 1136 | * 1137 | * Return: None. 1138 | * 1139 | * Notes: 1140 | * 1141 | -****************************************************************************/ 1142 | void AES_Test_ECB_D_MCT(CONST char *fname) 1143 | { 1144 | int i,j,q; 1145 | testData t; 1146 | 1147 | t.f=AES_PutFileHeader(fname, 1148 | "Electronic Codebook (ECB) Mode - DECRYPTION\nMonte Carlo Test"); 1149 | 1150 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 1151 | FatalError("cipherInit error during %s test",fname); 1152 | 1153 | for (t.keySize=KEY_BITS_0,q=0;t.keySize <= MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS,q+=2) 1154 | { 1155 | AES_printf(&t,"S\n"); /* output key size */ 1156 | if (!quietVerify) printf(" keyLen = %3d. ",t.keySize); 1157 | 1158 | ClearTestData(&t); /* start with all zeroes */ 1159 | if (makeKey(&t.ki,DIR_DECRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 1160 | FatalError("Error parsing key during %s test",fname); 1161 | 1162 | for (t.I=0;t.I=q) ? ((DWORD *)t.pt)[i-q] : 1174 | ((DWORD *)t.ct)[BLOCK_SIZE/32-q+i]); 1175 | BlockCopy(t.ct,t.pt); 1176 | } 1177 | AES_printf(&t,"P\n"); 1178 | if (reKey(&t.ki) != TRUE) 1179 | FatalError("reKey return during %s test",fname); 1180 | } 1181 | AES_EndSection(&t); 1182 | } 1183 | if (!quietVerify) printf(" \n"); 1184 | AES_Close(&t); 1185 | } 1186 | 1187 | /* 1188 | +***************************************************************************** 1189 | * 1190 | * Function Name: AES_Test_CBC_E_MCT 1191 | * 1192 | * Function: Run ECB Monte Carlo test for CBC encryption 1193 | * 1194 | * Arguments: fname = file name to produce 1195 | * 1196 | * Return: None. 1197 | * 1198 | * Notes: 1199 | * 1200 | -****************************************************************************/ 1201 | void AES_Test_CBC_E_MCT(CONST char *fname) 1202 | { 1203 | int i,j,q; 1204 | testData t; 1205 | BYTE ctPrev[BLOCK_SIZE/8]; 1206 | BYTE IV[BLOCK_SIZE/8]; 1207 | #define CV t.ci.IV /* use t.ci.IV as CV */ 1208 | 1209 | t.f=AES_PutFileHeader(fname, 1210 | "Cipher Block Chaining (CBC) Mode - ENCRYPTION\nMonte Carlo Test"); 1211 | 1212 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 1213 | FatalError("cipherInit error during %s test",fname); 1214 | 1215 | for (t.keySize=KEY_BITS_0,q=0;t.keySize<=MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS,q+=2) 1216 | { 1217 | AES_printf(&t,"S\n"); /* output key size */ 1218 | if (!quietVerify) printf(" keyLen = %3d. ",t.keySize); 1219 | 1220 | ClearTestData(&t); /* start with all zeroes */ 1221 | memset(IV,0,sizeof(IV)); 1222 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 1223 | FatalError("Error parsing key during %s test",fname); 1224 | 1225 | BlockCopy(CV,IV); 1226 | for (t.I=0;t.I=q) ? ((DWORD *)t.ct )[i-q] : 1246 | ((DWORD *)ctPrev)[BLOCK_SIZE/32-q+i]); 1247 | BlockCopy(t.pt,ctPrev); 1248 | BlockCopy(CV,t.ct); 1249 | 1250 | if (reKey(&t.ki) != TRUE) 1251 | FatalError("reKey return during %s test",fname); 1252 | } 1253 | AES_EndSection(&t); 1254 | } 1255 | if (!quietVerify) printf(" \n"); 1256 | AES_Close(&t); 1257 | } 1258 | 1259 | /* 1260 | +***************************************************************************** 1261 | * 1262 | * Function Name: AES_Test_CBC_D_MCT 1263 | * 1264 | * Function: Run ECB Monte Carlo test for CBC decryption 1265 | * 1266 | * Arguments: fname = file name to produce 1267 | * 1268 | * Return: None. 1269 | * 1270 | * Notes: 1271 | * 1272 | -****************************************************************************/ 1273 | void AES_Test_CBC_D_MCT(CONST char *fname) 1274 | { 1275 | int i,j,q; 1276 | testData t; 1277 | BYTE ptPrev[BLOCK_SIZE/8]; 1278 | BYTE IV[BLOCK_SIZE/8]; 1279 | #define CV t.ci.IV /* use t.ci.IV as CV */ 1280 | 1281 | t.f=AES_PutFileHeader(fname, 1282 | "Cipher Block Chaining (CBC) Mode - DECRYPTION\nMonte Carlo Test"); 1283 | 1284 | if (cipherInit(&t.ci,MODE_ECB,NULL) != TRUE) 1285 | FatalError("cipherInit error during %s test",fname); 1286 | 1287 | for (t.keySize=KEY_BITS_0,q=0;t.keySize <= MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS,q+=2) 1288 | { 1289 | AES_printf(&t,"S\n"); /* output key size */ 1290 | if (!quietVerify) printf(" keyLen = %3d. ",t.keySize); 1291 | 1292 | ClearTestData(&t); /* start with all zeroes */ 1293 | memset(IV,0,sizeof(IV)); 1294 | if (makeKey(&t.ki,DIR_DECRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 1295 | FatalError("Error parsing key during %s test",fname); 1296 | 1297 | BlockCopy(CV,IV); 1298 | for (t.I=0;t.I=q) ? ((DWORD *)t.pt )[i-q] : 1317 | ((DWORD *)ptPrev)[BLOCK_SIZE/32-q+i]); 1318 | if (reKey(&t.ki) != TRUE) 1319 | FatalError("reKey return during %s test",fname); 1320 | } 1321 | AES_EndSection(&t); 1322 | } 1323 | if (!quietVerify) printf(" \n"); 1324 | AES_Close(&t); 1325 | } 1326 | 1327 | /* 1328 | +***************************************************************************** 1329 | * 1330 | * Function Name: ShowParams 1331 | * 1332 | * Function: Print out the settings of settable parameters 1333 | * 1334 | * Arguments: None. 1335 | * 1336 | * Return: None. 1337 | * 1338 | * Notes: 1339 | * 1340 | -****************************************************************************/ 1341 | void ShowParams(void) 1342 | { 1343 | int saveDebug=debug; 1344 | testData t; 1345 | 1346 | debug=0; /* turn off debug output */ 1347 | memset(t.ki.keyMaterial,'0',sizeof(t.ki.keyMaterial)); 1348 | 1349 | printf("(keyLen,numRounds): "); 1350 | for (t.keySize=KEY_BITS_0;t.keySize<=MAX_KEY_BITS;t.keySize+=STEP_KEY_BITS) 1351 | { 1352 | if (makeKey(&t.ki,DIR_ENCRYPT,t.keySize,t.ki.keyMaterial) != TRUE) 1353 | FatalError("Error parsing key during ShowParam",""); 1354 | printf(" (%d,%d)",t.keySize,t.ki.numRounds); 1355 | } 1356 | printf("\n"); 1357 | debug=saveDebug; 1358 | } 1359 | 1360 | /* 1361 | +***************************************************************************** 1362 | * 1363 | * Function Name: ParseArgFile 1364 | * 1365 | * Function: Parse commands from argument file 1366 | * 1367 | * Arguments: fName = name of file to read 1368 | * argList = list of ptrs to fill in 1369 | * maxArgCnt = size of argList 1370 | * 1371 | * Return: None. 1372 | * 1373 | * Notes: '/' and ';' are comment to end of line characters in the file 1374 | * This function is used to allow a "custom" set of switches to 1375 | * be automatically read from a file at startup. 1376 | * 1377 | -****************************************************************************/ 1378 | int ParseArgFile(CONST char *fName,char *argList[],int maxArgCnt) 1379 | { 1380 | static char buf[1024]; 1381 | static int bufCnt=0; /* current # chars in buf */ 1382 | 1383 | int i,j,k,argCnt; 1384 | char line[256]; 1385 | FILE *f=fopen(fName,"rt"); 1386 | 1387 | if (f == NULL) return 0; 1388 | if (debug) printf("Reading args from file %s: ",fName); 1389 | 1390 | for (argCnt=0;argCnt ' ') break; 1402 | if (line[j]==0) break; 1403 | for (k=j;line[k];k++) 1404 | if (line[k] <= ' ') break; 1405 | /* now j..k-1 defines a token */ 1406 | if (k-j+1 > (int)(sizeof(buf) - bufCnt)) 1407 | FatalError("Arg file too large: %s",line); 1408 | if (argCnt >= maxArgCnt) 1409 | break; 1410 | memcpy(buf+bufCnt,line+j,k-j); 1411 | buf[bufCnt+k-j]=0; /* terminate the token */ 1412 | if (debug) printf(" %s",buf+bufCnt); 1413 | argList[argCnt++]=buf+bufCnt; 1414 | bufCnt+=k-j+1; 1415 | i=k; /* skip to next token */ 1416 | } 1417 | } 1418 | fclose(f); 1419 | if (debug) printf("\n"); 1420 | return argCnt; 1421 | } 1422 | 1423 | /* 1424 | +***************************************************************************** 1425 | * 1426 | * Function Name: GiveHelp 1427 | * 1428 | * Function: Print out list of command line switches 1429 | * 1430 | * Arguments: None. 1431 | * 1432 | * Return: None. 1433 | * 1434 | * Notes: 1435 | * 1436 | -****************************************************************************/ 1437 | void GiveHelp(void) 1438 | { 1439 | printf("Syntax: TST2FISH [options]\n" 1440 | "Purpose: Generate/validate AES Twofish code and files\n" 1441 | "Options: -lNN ==> set sanity check loop to NN\n" 1442 | " -m ==> do full MCT generation\n" 1443 | " -pPath ==> set file path\n" 1444 | " -s ==> set initial random seed based on time\n" 1445 | " -sNN ==> set initial random seed to NN\n" 1446 | " -tNN ==> time performance using NN iterations\n" 1447 | " -v ==> validate files, don't generate them\n", 1448 | MAX_ROUNDS 1449 | ); 1450 | exit(1); 1451 | } 1452 | 1453 | #ifdef TEST_EXTERN 1454 | void Test_Extern(void); 1455 | #endif 1456 | 1457 | void ShowHex(FILE *f,CONST void *p,int bCnt,CONST char *name) 1458 | { 1459 | int i; 1460 | 1461 | fprintf(f," ;%s:",name); 1462 | for (i=0;i check all parameters */ 32 | #define FEISTEL 0 /* nonzero --> use Feistel version (slow) */ 33 | 34 | int tabEnable=0; /* are we gathering stats? */ 35 | BYTE tabUsed[256]; /* one bit per table */ 36 | 37 | #if FEISTEL 38 | CONST char *moduleDescription="Pedagogical C code (Feistel)"; 39 | #else 40 | CONST char *moduleDescription="Pedagogical C code"; 41 | #endif 42 | CONST char *modeString = ""; 43 | 44 | #define P0_USED 0x01 45 | #define P1_USED 0x02 46 | #define B0_USED 0x04 47 | #define B1_USED 0x08 48 | #define B2_USED 0x10 49 | #define B3_USED 0x20 50 | #define ALL_USED 0x3F 51 | 52 | /* number of rounds for various key sizes: 128, 192, 256 */ 53 | int numRounds[4]= {0,ROUNDS_128,ROUNDS_192,ROUNDS_256}; 54 | 55 | #ifndef DEBUG 56 | #ifdef GetCodeSize 57 | #define DEBUG 1 /* force debug */ 58 | #endif 59 | #endif 60 | #include "debug.h" /* debug display macros */ 61 | 62 | #ifdef GetCodeSize 63 | extern DWORD Here(DWORD x); /* return caller's address! */ 64 | DWORD TwofishCodeStart(void) { return Here(0); }; 65 | #endif 66 | 67 | /* 68 | +***************************************************************************** 69 | * 70 | * Function Name: TableOp 71 | * 72 | * Function: Handle table use checking 73 | * 74 | * Arguments: op = what to do (see TAB_* defns in AES.H) 75 | * 76 | * Return: TRUE --> done (for TAB_QUERY) 77 | * 78 | * Notes: This routine is for use in generating the tables KAT file. 79 | * 80 | -****************************************************************************/ 81 | int TableOp(int op) 82 | { 83 | static int queryCnt=0; 84 | int i; 85 | switch (op) 86 | { 87 | case TAB_DISABLE: 88 | tabEnable=0; 89 | break; 90 | case TAB_ENABLE: 91 | tabEnable=1; 92 | break; 93 | case TAB_RESET: 94 | queryCnt=0; 95 | for (i=0;i<256;i++) 96 | tabUsed[i]=0; 97 | break; 98 | case TAB_QUERY: 99 | queryCnt++; 100 | for (i=0;i<256;i++) 101 | if (tabUsed[i] != ALL_USED) 102 | return FALSE; 103 | if (queryCnt < TAB_MIN_QUERY) /* do a certain minimum number */ 104 | return FALSE; 105 | break; 106 | } 107 | return TRUE; 108 | } 109 | 110 | 111 | /* 112 | +***************************************************************************** 113 | * 114 | * Function Name: ParseHexDword 115 | * 116 | * Function: Parse ASCII hex nibbles and fill in key/iv dwords 117 | * 118 | * Arguments: bit = # bits to read 119 | * srcTxt = ASCII source 120 | * d = ptr to dwords to fill in 121 | * dstTxt = where to make a copy of ASCII source 122 | * (NULL ok) 123 | * 124 | * Return: Zero if no error. Nonzero --> invalid hex or length 125 | * 126 | * Notes: Note that the parameter d is a DWORD array, not a byte array. 127 | * This routine is coded to work both for little-endian and big-endian 128 | * architectures. The character stream is interpreted as a LITTLE-ENDIAN 129 | * byte stream, since that is how the Pentium works, but the conversion 130 | * happens automatically below. 131 | * 132 | -****************************************************************************/ 133 | int ParseHexDword(int bits,CONST char *srcTxt,DWORD *d,char *dstTxt) 134 | { 135 | int i; 136 | DWORD b; 137 | char c; 138 | #if ALIGN32 139 | char alignDummy[3]; /* keep dword alignment */ 140 | #endif 141 | 142 | union /* make sure LittleEndian is defined correctly */ 143 | { 144 | BYTE b[4]; 145 | DWORD d[1]; 146 | } v; 147 | v.d[0]=1; 148 | if (v.b[0 ^ ADDR_XOR] != 1) /* sanity check on compile-time switch */ 149 | return BAD_ENDIAN; 150 | 151 | #if VALIDATE_PARMS 152 | #if ALIGN32 153 | if (((int)d) & 3) 154 | return BAD_ALIGN32; 155 | #endif 156 | #endif 157 | 158 | for (i=0;i*32= '0') && (c <= '9')) 166 | b=c-'0'; 167 | else if ((c >= 'a') && (c <= 'f')) 168 | b=c-'a'+10; 169 | else if ((c >= 'A') && (c <= 'F')) 170 | b=c-'A'+10; 171 | else 172 | return BAD_KEY_MAT; /* invalid hex character */ 173 | /* works for big and little endian! */ 174 | d[i/8] |= b << (4*((i^1)&7)); 175 | } 176 | 177 | return 0; /* no error */ 178 | } 179 | 180 | 181 | /* 182 | +***************************************************************************** 183 | * 184 | * Function Name: f32 185 | * 186 | * Function: Run four bytes through keyed S-boxes and apply MDS matrix 187 | * 188 | * Arguments: x = input to f function 189 | * k32 = pointer to key dwords 190 | * keyLen = total key length (k32 --> keyLey/2 bits) 191 | * 192 | * Return: The output of the keyed permutation applied to x. 193 | * 194 | * Notes: 195 | * This function is a keyed 32-bit permutation. It is the major building 196 | * block for the Twofish round function, including the four keyed 8x8 197 | * permutations and the 4x4 MDS matrix multiply. This function is used 198 | * both for generating round subkeys and within the round function on the 199 | * block being encrypted. 200 | * 201 | * This version is fairly slow and pedagogical, although a smartcard would 202 | * probably perform the operation exactly this way in firmware. For 203 | * ultimate performance, the entire operation can be completed with four 204 | * lookups into four 256x32-bit tables, with three dword xors. 205 | * 206 | * The MDS matrix is defined in TABLE.H. To multiply by Mij, just use the 207 | * macro Mij(x). 208 | * 209 | -****************************************************************************/ 210 | DWORD f32(DWORD x,CONST DWORD *k32,int keyLen) 211 | { 212 | BYTE b[4]; 213 | 214 | /* Run each byte thru 8x8 S-boxes, xoring with key byte at each stage. */ 215 | /* Note that each byte goes through a different combination of S-boxes.*/ 216 | 217 | *((DWORD *)b) = Bswap(x); /* make b[0] = LSB, b[3] = MSB */ 218 | switch (((keyLen + 63)/64) & 3) 219 | { 220 | case 0: /* 256 bits of key */ 221 | b[0] = p8(04)[b[0]] ^ b0(k32[3]); 222 | b[1] = p8(14)[b[1]] ^ b1(k32[3]); 223 | b[2] = p8(24)[b[2]] ^ b2(k32[3]); 224 | b[3] = p8(34)[b[3]] ^ b3(k32[3]); 225 | /* fall thru, having pre-processed b[0]..b[3] with k32[3] */ 226 | case 3: /* 192 bits of key */ 227 | b[0] = p8(03)[b[0]] ^ b0(k32[2]); 228 | b[1] = p8(13)[b[1]] ^ b1(k32[2]); 229 | b[2] = p8(23)[b[2]] ^ b2(k32[2]); 230 | b[3] = p8(33)[b[3]] ^ b3(k32[2]); 231 | /* fall thru, having pre-processed b[0]..b[3] with k32[2] */ 232 | case 2: /* 128 bits of key */ 233 | b[0] = p8(00)[p8(01)[p8(02)[b[0]] ^ b0(k32[1])] ^ b0(k32[0])]; 234 | b[1] = p8(10)[p8(11)[p8(12)[b[1]] ^ b1(k32[1])] ^ b1(k32[0])]; 235 | b[2] = p8(20)[p8(21)[p8(22)[b[2]] ^ b2(k32[1])] ^ b2(k32[0])]; 236 | b[3] = p8(30)[p8(31)[p8(32)[b[3]] ^ b3(k32[1])] ^ b3(k32[0])]; 237 | } 238 | 239 | if (tabEnable) 240 | { /* we could give a "tighter" bound, but this works acceptably well */ 241 | tabUsed[b0(x)] |= (P_00 == 0) ? P0_USED : P1_USED; 242 | tabUsed[b1(x)] |= (P_10 == 0) ? P0_USED : P1_USED; 243 | tabUsed[b2(x)] |= (P_20 == 0) ? P0_USED : P1_USED; 244 | tabUsed[b3(x)] |= (P_30 == 0) ? P0_USED : P1_USED; 245 | 246 | tabUsed[b[0] ] |= B0_USED; 247 | tabUsed[b[1] ] |= B1_USED; 248 | tabUsed[b[2] ] |= B2_USED; 249 | tabUsed[b[3] ] |= B3_USED; 250 | } 251 | 252 | /* Now perform the MDS matrix multiply inline. */ 253 | return ((M00(b[0]) ^ M01(b[1]) ^ M02(b[2]) ^ M03(b[3])) ) ^ 254 | ((M10(b[0]) ^ M11(b[1]) ^ M12(b[2]) ^ M13(b[3])) << 8) ^ 255 | ((M20(b[0]) ^ M21(b[1]) ^ M22(b[2]) ^ M23(b[3])) << 16) ^ 256 | ((M30(b[0]) ^ M31(b[1]) ^ M32(b[2]) ^ M33(b[3])) << 24) ; 257 | } 258 | 259 | /* 260 | +***************************************************************************** 261 | * 262 | * Function Name: RS_MDS_Encode 263 | * 264 | * Function: Use (12,8) Reed-Solomon code over GF(256) to produce 265 | * a key S-box dword from two key material dwords. 266 | * 267 | * Arguments: k0 = 1st dword 268 | * k1 = 2nd dword 269 | * 270 | * Return: Remainder polynomial generated using RS code 271 | * 272 | * Notes: 273 | * Since this computation is done only once per reKey per 64 bits of key, 274 | * the performance impact of this routine is imperceptible. The RS code 275 | * chosen has "simple" coefficients to allow smartcard/hardware implementation 276 | * without lookup tables. 277 | * 278 | -****************************************************************************/ 279 | DWORD RS_MDS_Encode(DWORD k0,DWORD k1) 280 | { 281 | int i,j; 282 | DWORD r; 283 | 284 | for (i=r=0;i<2;i++) 285 | { 286 | r ^= (i) ? k0 : k1; /* merge in 32 more key bits */ 287 | for (j=0;j<4;j++) /* shift one byte at a time */ 288 | RS_rem(r); 289 | } 290 | return r; 291 | } 292 | 293 | /* 294 | +***************************************************************************** 295 | * 296 | * Function Name: reKey 297 | * 298 | * Function: Initialize the Twofish key schedule from key32 299 | * 300 | * Arguments: key = ptr to keyInstance to be initialized 301 | * 302 | * Return: TRUE on success 303 | * 304 | * Notes: 305 | * Here we precompute all the round subkeys, although that is not actually 306 | * required. For example, on a smartcard, the round subkeys can 307 | * be generated on-the-fly using f32() 308 | * 309 | -****************************************************************************/ 310 | int reKey(keyInstance *key) 311 | { 312 | int i,k64Cnt; 313 | int keyLen = key->keyLen; 314 | int subkeyCnt = ROUND_SUBKEYS + 2*key->numRounds; 315 | DWORD A,B; 316 | DWORD k32e[MAX_KEY_BITS/64],k32o[MAX_KEY_BITS/64]; /* even/odd key dwords */ 317 | 318 | #if VALIDATE_PARMS 319 | #if ALIGN32 320 | if ((((int)key) & 3) || (((int)key->key32) & 3)) 321 | return BAD_ALIGN32; 322 | #endif 323 | if ((key->keyLen % 64) || (key->keyLen < MIN_KEY_BITS)) 324 | return BAD_KEY_INSTANCE; 325 | if (subkeyCnt > TOTAL_SUBKEYS) 326 | return BAD_KEY_INSTANCE; 327 | #endif 328 | 329 | k64Cnt=(keyLen+63)/64; /* round up to next multiple of 64 bits */ 330 | for (i=0;ikey32[2*i ]; 333 | k32o[i]=key->key32[2*i+1]; 334 | /* compute S-box keys using (12,8) Reed-Solomon code over GF(256) */ 335 | key->sboxKeys[k64Cnt-1-i]=RS_MDS_Encode(k32e[i],k32o[i]); /* reverse order */ 336 | } 337 | 338 | for (i=0;isubKeys[2*i ] = A+ B; /* combine with a PHT */ 344 | key->subKeys[2*i+1] = ROL(A+2*B,SK_ROTL); 345 | } 346 | 347 | DebugDumpKey(key); 348 | 349 | return TRUE; 350 | } 351 | /* 352 | +***************************************************************************** 353 | * 354 | * Function Name: makeKey 355 | * 356 | * Function: Initialize the Twofish key schedule 357 | * 358 | * Arguments: key = ptr to keyInstance to be initialized 359 | * direction = DIR_ENCRYPT or DIR_DECRYPT 360 | * keyLen = # bits of key text at *keyMaterial 361 | * keyMaterial = ptr to hex ASCII chars representing key bits 362 | * 363 | * Return: TRUE on success 364 | * else error code (e.g., BAD_KEY_DIR) 365 | * 366 | * Notes: 367 | * This parses the key bits from keyMaterial. No crypto stuff happens here. 368 | * The function reKey() is called to actually build the key schedule after 369 | * the keyMaterial has been parsed. 370 | * 371 | -****************************************************************************/ 372 | int makeKey(keyInstance *key, BYTE direction, int keyLen,CONST char *keyMaterial) 373 | { 374 | int i; 375 | 376 | #if VALIDATE_PARMS /* first, sanity check on parameters */ 377 | if (key == NULL) 378 | return BAD_KEY_INSTANCE;/* must have a keyInstance to initialize */ 379 | if ((direction != DIR_ENCRYPT) && (direction != DIR_DECRYPT)) 380 | return BAD_KEY_DIR; /* must have valid direction */ 381 | if ((keyLen > MAX_KEY_BITS) || (keyLen < 8)) 382 | return BAD_KEY_MAT; /* length must be valid */ 383 | key->keySig = VALID_SIG; /* show that we are initialized */ 384 | #if ALIGN32 385 | if ((((int)key) & 3) || (((int)key->key32) & 3)) 386 | return BAD_ALIGN32; 387 | #endif 388 | #endif 389 | 390 | key->direction = direction; /* set our cipher direction */ 391 | key->keyLen = (keyLen+63) & ~63; /* round up to multiple of 64 */ 392 | key->numRounds = numRounds[(keyLen-1)/64]; 393 | for (i=0;ikey32[i]=0; 395 | key->keyMaterial[MAX_KEY_SIZE]=0; /* terminate ASCII string */ 396 | 397 | if ((keyMaterial == NULL) || (keyMaterial[0]==0)) 398 | return TRUE; /* allow a "dummy" call */ 399 | 400 | if (ParseHexDword(keyLen,keyMaterial,key->key32,key->keyMaterial)) 401 | return BAD_KEY_MAT; 402 | 403 | return reKey(key); /* generate round subkeys */ 404 | } 405 | 406 | 407 | /* 408 | +***************************************************************************** 409 | * 410 | * Function Name: cipherInit 411 | * 412 | * Function: Initialize the Twofish cipher in a given mode 413 | * 414 | * Arguments: cipher = ptr to cipherInstance to be initialized 415 | * mode = MODE_ECB, MODE_CBC, or MODE_CFB1 416 | * IV = ptr to hex ASCII test representing IV bytes 417 | * 418 | * Return: TRUE on success 419 | * else error code (e.g., BAD_CIPHER_MODE) 420 | * 421 | -****************************************************************************/ 422 | int cipherInit(cipherInstance *cipher, BYTE mode,CONST char *IV) 423 | { 424 | int i; 425 | #if VALIDATE_PARMS /* first, sanity check on parameters */ 426 | if (cipher == NULL) 427 | return BAD_PARAMS; /* must have a cipherInstance to initialize */ 428 | if ((mode != MODE_ECB) && (mode != MODE_CBC) && (mode != MODE_CFB1)) 429 | return BAD_CIPHER_MODE; /* must have valid cipher mode */ 430 | cipher->cipherSig = VALID_SIG; 431 | #if ALIGN32 432 | if ((((int)cipher) & 3) || (((int)cipher->IV) & 3) || (((int)cipher->iv32) & 3)) 433 | return BAD_ALIGN32; 434 | #endif 435 | #endif 436 | 437 | if ((mode != MODE_ECB) && (IV)) /* parse the IV */ 438 | { 439 | if (ParseHexDword(BLOCK_SIZE,IV,cipher->iv32,NULL)) 440 | return BAD_IV_MAT; 441 | for (i=0;iIV)[i] = Bswap(cipher->iv32[i]); 443 | } 444 | 445 | cipher->mode = mode; 446 | 447 | return TRUE; 448 | } 449 | 450 | /* 451 | +***************************************************************************** 452 | * 453 | * Function Name: blockEncrypt 454 | * 455 | * Function: Encrypt block(s) of data using Twofish 456 | * 457 | * Arguments: cipher = ptr to already initialized cipherInstance 458 | * key = ptr to already initialized keyInstance 459 | * input = ptr to data blocks to be encrypted 460 | * inputLen = # bits to encrypt (multiple of blockSize) 461 | * outBuffer = ptr to where to put encrypted blocks 462 | * 463 | * Return: # bits ciphered (>= 0) 464 | * else error code (e.g., BAD_CIPHER_STATE, BAD_KEY_MATERIAL) 465 | * 466 | * Notes: The only supported block size for ECB/CBC modes is BLOCK_SIZE bits. 467 | * If inputLen is not a multiple of BLOCK_SIZE bits in those modes, 468 | * an error BAD_INPUT_LEN is returned. In CFB1 mode, all block 469 | * sizes can be supported. 470 | * 471 | -****************************************************************************/ 472 | int blockEncrypt(cipherInstance *cipher, keyInstance *key,CONST BYTE *input, 473 | int inputLen, BYTE *outBuffer) 474 | { 475 | int i,n,r; /* loop variables */ 476 | DWORD x[BLOCK_SIZE/32]; /* block being encrypted */ 477 | DWORD t0,t1,tmp; /* temp variables */ 478 | int rounds=key->numRounds; /* number of rounds */ 479 | BYTE bit,ctBit,carry; /* temps for CFB */ 480 | #if ALIGN32 481 | BYTE alignDummy; /* keep 32-bit variable alignment on stack */ 482 | #endif 483 | 484 | #if VALIDATE_PARMS 485 | if ((cipher == NULL) || (cipher->cipherSig != VALID_SIG)) 486 | return BAD_CIPHER_STATE; 487 | if ((key == NULL) || (key->keySig != VALID_SIG)) 488 | return BAD_KEY_INSTANCE; 489 | if ((rounds < 2) || (rounds > MAX_ROUNDS) || (rounds&1)) 490 | return BAD_KEY_INSTANCE; 491 | if ((cipher->mode != MODE_CFB1) && (inputLen % BLOCK_SIZE)) 492 | return BAD_INPUT_LEN; 493 | #if ALIGN32 494 | if ( (((int)cipher) & 3) || (((int)key ) & 3) || 495 | (((int)input ) & 3) || (((int)outBuffer) & 3)) 496 | return BAD_ALIGN32; 497 | #endif 498 | #endif 499 | 500 | if (cipher->mode == MODE_CFB1) 501 | { /* use recursion here to handle CFB, one block at a time */ 502 | cipher->mode = MODE_ECB; /* do encryption in ECB */ 503 | for (n=0;nIV,BLOCK_SIZE,(BYTE *)x); 506 | bit = 0x80 >> (n & 7);/* which bit position in byte */ 507 | ctBit = (input[n/8] & bit) ^ ((((BYTE *) x)[0] & 0x80) >> (n&7)); 508 | outBuffer[n/8] = (outBuffer[n/8] & ~ bit) | ctBit; 509 | carry = ctBit >> (7 - (n&7)); 510 | for (i=BLOCK_SIZE/8-1;i>=0;i--) 511 | { 512 | bit = cipher->IV[i] >> 7; /* save next "carry" from shift */ 513 | cipher->IV[i] = (cipher->IV[i] << 1) ^ carry; 514 | carry = bit; 515 | } 516 | } 517 | cipher->mode = MODE_CFB1; /* restore mode for next time */ 518 | return inputLen; 519 | } 520 | 521 | /* here for ECB, CBC modes */ 522 | for (n=0;nmode == MODE_CBC) 527 | DebugDump(cipher->iv32,"",IV_ROUND,0,0,0,0); 528 | #endif 529 | for (i=0;isubKeys[INPUT_WHITEN+i]; 532 | if (cipher->mode == MODE_CBC) 533 | x[i] ^= Bswap(cipher->iv32[i]); 534 | } 535 | 536 | DebugDump(x,"",0,0,0,0,0); 537 | for (r=0;rsboxKeys,key->keyLen); 541 | t1 = f32(ROL(x[1],8+(r+1)/2),key->sboxKeys,key->keyLen); 542 | /* PHT, round keys */ 543 | x[2]^= ROL(t0 + t1 + key->subKeys[ROUND_SUBKEYS+2*r ], r /2); 544 | x[3]^= ROR(t0 + 2*t1 + key->subKeys[ROUND_SUBKEYS+2*r+1],(r+2) /2); 545 | 546 | DebugDump(x,"",r+1,2*(r&1),1,1,0); 547 | #else 548 | t0 = f32( x[0] ,key->sboxKeys,key->keyLen); 549 | t1 = f32(ROL(x[1],8),key->sboxKeys,key->keyLen); 550 | 551 | x[3] = ROL(x[3],1); 552 | x[2]^= t0 + t1 + key->subKeys[ROUND_SUBKEYS+2*r ]; /* PHT, round keys */ 553 | x[3]^= t0 + 2*t1 + key->subKeys[ROUND_SUBKEYS+2*r+1]; 554 | x[2] = ROR(x[2],1); 555 | 556 | DebugDump(x,"",r+1,2*(r&1),0,1,0);/* make format compatible with optimized code */ 557 | #endif 558 | if (r < rounds-1) /* swap for next round */ 559 | { 560 | tmp = x[0]; x[0]= x[2]; x[2] = tmp; 561 | tmp = x[1]; x[1]= x[3]; x[3] = tmp; 562 | } 563 | } 564 | #if FEISTEL 565 | x[0] = ROR(x[0],8); /* "final permutation" */ 566 | x[1] = ROL(x[1],8); 567 | x[2] = ROR(x[2],8); 568 | x[3] = ROL(x[3],8); 569 | #endif 570 | for (i=0;isubKeys[OUTPUT_WHITEN+i]); 573 | if (cipher->mode == MODE_CBC) 574 | cipher->iv32[i] = ((DWORD *)outBuffer)[i]; 575 | } 576 | #ifdef DEBUG 577 | DebugDump(outBuffer,"",rounds+1,0,0,0,1); 578 | if (cipher->mode == MODE_CBC) 579 | DebugDump(cipher->iv32,"",IV_ROUND,0,0,0,0); 580 | #endif 581 | } 582 | 583 | return inputLen; 584 | } 585 | 586 | /* 587 | +***************************************************************************** 588 | * 589 | * Function Name: blockDecrypt 590 | * 591 | * Function: Decrypt block(s) of data using Twofish 592 | * 593 | * Arguments: cipher = ptr to already initialized cipherInstance 594 | * key = ptr to already initialized keyInstance 595 | * input = ptr to data blocks to be decrypted 596 | * inputLen = # bits to encrypt (multiple of blockSize) 597 | * outBuffer = ptr to where to put decrypted blocks 598 | * 599 | * Return: # bits ciphered (>= 0) 600 | * else error code (e.g., BAD_CIPHER_STATE, BAD_KEY_MATERIAL) 601 | * 602 | * Notes: The only supported block size for ECB/CBC modes is BLOCK_SIZE bits. 603 | * If inputLen is not a multiple of BLOCK_SIZE bits in those modes, 604 | * an error BAD_INPUT_LEN is returned. In CFB1 mode, all block 605 | * sizes can be supported. 606 | * 607 | -****************************************************************************/ 608 | int blockDecrypt(cipherInstance *cipher, keyInstance *key,CONST BYTE *input, 609 | int inputLen, BYTE *outBuffer) 610 | { 611 | int i,n,r; /* loop counters */ 612 | DWORD x[BLOCK_SIZE/32]; /* block being encrypted */ 613 | DWORD t0,t1; /* temp variables */ 614 | int rounds=key->numRounds; /* number of rounds */ 615 | BYTE bit,ctBit,carry; /* temps for CFB */ 616 | #if ALIGN32 617 | BYTE alignDummy; /* keep 32-bit variable alignment on stack */ 618 | #endif 619 | 620 | #if VALIDATE_PARMS 621 | if ((cipher == NULL) || (cipher->cipherSig != VALID_SIG)) 622 | return BAD_CIPHER_STATE; 623 | if ((key == NULL) || (key->keySig != VALID_SIG)) 624 | return BAD_KEY_INSTANCE; 625 | if ((rounds < 2) || (rounds > MAX_ROUNDS) || (rounds&1)) 626 | return BAD_KEY_INSTANCE; 627 | if ((cipher->mode != MODE_CFB1) && (inputLen % BLOCK_SIZE)) 628 | return BAD_INPUT_LEN; 629 | #if ALIGN32 630 | if ( (((int)cipher) & 3) || (((int)key ) & 3) || 631 | (((int)input) & 3) || (((int)outBuffer) & 3)) 632 | return BAD_ALIGN32; 633 | #endif 634 | #endif 635 | 636 | if (cipher->mode == MODE_CFB1) 637 | { /* use blockEncrypt here to handle CFB, one block at a time */ 638 | cipher->mode = MODE_ECB; /* do encryption in ECB */ 639 | for (n=0;nIV,BLOCK_SIZE,(BYTE *)x); 642 | bit = 0x80 >> (n & 7); 643 | ctBit = input[n/8] & bit; 644 | outBuffer[n/8] = (outBuffer[n/8] & ~ bit) | 645 | (ctBit ^ ((((BYTE *) x)[0] & 0x80) >> (n&7))); 646 | carry = ctBit >> (7 - (n&7)); 647 | for (i=BLOCK_SIZE/8-1;i>=0;i--) 648 | { 649 | bit = cipher->IV[i] >> 7; /* save next "carry" from shift */ 650 | cipher->IV[i] = (cipher->IV[i] << 1) ^ carry; 651 | carry = bit; 652 | } 653 | } 654 | cipher->mode = MODE_CFB1; /* restore mode for next time */ 655 | return inputLen; 656 | } 657 | 658 | /* here for ECB, CBC modes */ 659 | for (n=0;nsubKeys[OUTPUT_WHITEN+i]; 665 | 666 | for (r=rounds-1;r>=0;r--) /* main Twofish decryption loop */ 667 | { 668 | t0 = f32( x[0] ,key->sboxKeys,key->keyLen); 669 | t1 = f32(ROL(x[1],8),key->sboxKeys,key->keyLen); 670 | 671 | DebugDump(x,"",r+1,2*(r&1),0,1,0);/* make format compatible with optimized code */ 672 | x[2] = ROL(x[2],1); 673 | x[2]^= t0 + t1 + key->subKeys[ROUND_SUBKEYS+2*r ]; /* PHT, round keys */ 674 | x[3]^= t0 + 2*t1 + key->subKeys[ROUND_SUBKEYS+2*r+1]; 675 | x[3] = ROR(x[3],1); 676 | 677 | if (r) /* unswap, except for last round */ 678 | { 679 | t0 = x[0]; x[0]= x[2]; x[2] = t0; 680 | t1 = x[1]; x[1]= x[3]; x[3] = t1; 681 | } 682 | } 683 | DebugDump(x,"",0,0,0,0,0);/* make final output match encrypt initial output */ 684 | 685 | for (i=0;isubKeys[INPUT_WHITEN+i]; 688 | if (cipher->mode == MODE_CBC) 689 | { 690 | x[i] ^= Bswap(cipher->iv32[i]); 691 | cipher->iv32[i] = ((DWORD *)input)[i]; 692 | } 693 | ((DWORD *)outBuffer)[i] = Bswap(x[i]); 694 | } 695 | DebugDump(outBuffer,"",-1,0,0,0,1); 696 | } 697 | 698 | return inputLen; 699 | } 700 | 701 | 702 | #ifdef GetCodeSize 703 | DWORD TwofishCodeSize(void) { return Here(0)-TwofishCodeStart(); }; 704 | #endif 705 | -------------------------------------------------------------------------------- /Encryption_Algorithms/Vernam_one_time_pad.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 10, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Enter Plain Text: 110101010\n", 13 | "Encrypted: 111100111\n", 14 | "Decrypted: 110101010\n" 15 | ] 16 | } 17 | ], 18 | "source": [ 19 | "import random \n", 20 | "x=input(\"Enter Plain Text: \")\n", 21 | "\n", 22 | "key=[random.randint(0, 1)for i in range(len(x))]\n", 23 | "encmsg=\"\"\n", 24 | "decmsg=\"\"\n", 25 | "for i in range(len(x)):\n", 26 | " encmsg+=str(int(x[i])^key[i])\n", 27 | "for i in range(len(x)):\n", 28 | " decmsg+=str(int(encmsg[i])^key[i]) \n", 29 | "print(\"Encrypted: \",encmsg)\n", 30 | "print(\"Decrypted: \",decmsg)\n", 31 | "\n", 32 | " \n", 33 | " \n", 34 | " \n", 35 | " " 36 | ] 37 | }, 38 | { 39 | "cell_type": "code", 40 | "execution_count": null, 41 | "metadata": {}, 42 | "outputs": [], 43 | "source": [] 44 | } 45 | ], 46 | "metadata": { 47 | "kernelspec": { 48 | "display_name": "Python 3", 49 | "language": "python", 50 | "name": "python3" 51 | }, 52 | "language_info": { 53 | "codemirror_mode": { 54 | "name": "ipython", 55 | "version": 3 56 | }, 57 | "file_extension": ".py", 58 | "mimetype": "text/x-python", 59 | "name": "python", 60 | "nbconvert_exporter": "python", 61 | "pygments_lexer": "ipython3", 62 | "version": "3.7.6" 63 | } 64 | }, 65 | "nbformat": 4, 66 | "nbformat_minor": 4 67 | } 68 | -------------------------------------------------------------------------------- /Encryption_Algorithms/cieser-cipher-encryption_in_c.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() 4 | { 5 | char message[100], ch; 6 | int i, key; 7 | 8 | printf("Enter a message to encrypt: "); 9 | gets(message); 10 | printf("Enter key: "); 11 | scanf("%d", &key); 12 | 13 | for(i = 0; message[i] != '\0'; ++i){ 14 | ch = message[i]; 15 | 16 | if(ch >= 'a' && ch <= 'z'){ 17 | ch = ch + key; 18 | 19 | if(ch > 'z'){ 20 | ch = ch - 'z' + 'a' - 1; 21 | } 22 | 23 | message[i] = ch; 24 | } 25 | else if(ch >= 'A' && ch <= 'Z'){ 26 | ch = ch + key; 27 | 28 | if(ch > 'Z'){ 29 | ch = ch - 'Z' + 'A' - 1; 30 | } 31 | 32 | message[i] = ch; 33 | } 34 | } 35 | 36 | printf("Encrypted message: %s", message); 37 | 38 | return 0; 39 | printf("Enter a message to decrypt: "); 40 | gets(message); 41 | printf("Enter key: "); 42 | scanf("%d", &key); 43 | 44 | for(i = 0; message[i] != '\0'; ++i){ 45 | ch = message[i]; 46 | 47 | if(ch >= 'a' && ch <= 'z'){ 48 | ch = ch - key; 49 | 50 | if(ch < 'a'){ 51 | ch = ch + 'z' - 'a' + 1; 52 | } 53 | 54 | message[i] = ch; 55 | } 56 | else if(ch >= 'A' && ch <= 'Z'){ 57 | ch = ch - key; 58 | 59 | if(ch < 'A'){ 60 | ch = ch + 'Z' - 'A' + 1; 61 | } 62 | 63 | message[i] = ch; 64 | } 65 | } 66 | 67 | printf("Decrypted message: %s", message); 68 | 69 | return 0; 70 | } 71 | -------------------------------------------------------------------------------- /Encryption_Algorithms/cypherTextUsingKey(Basic).ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 19, 6 | "metadata": {}, 7 | "outputs": [ 8 | { 9 | "name": "stdout", 10 | "output_type": "stream", 11 | "text": [ 12 | "Enter Message: hello\n", 13 | "Enter Key: 4\n", 14 | "Choose The following Option: \n", 15 | "1: Encrypt The Message \n", 16 | "2: Decrypt The Message\n", 17 | "Choice: 1\n", 18 | "Encrypted Message: lipps\n" 19 | ] 20 | } 21 | ], 22 | "source": [ 23 | "msg=input(\"Enter Message: \")\n", 24 | "key=int(input(\"Enter Key: \"))\n", 25 | "print(\"Choose The following Option: \\n1: Encrypt The Message \\n2: Decrypt The Message\")\n", 26 | "x=int(input(\"Choice: \"))\n", 27 | "if(x==1):\n", 28 | " encmsg=\"\"\n", 29 | " for i in msg:\n", 30 | " if(i.isupper()):\n", 31 | " encmsg+=chr((ord(i)+key-65)%26+65)\n", 32 | " else:\n", 33 | " encmsg+=chr((ord(i)+key-97)%26+97)\n", 34 | " \n", 35 | " print(\"Encrypted Message: \"+encmsg)\n", 36 | "else:\n", 37 | " decmsg=\"\"\n", 38 | " for i in msg:\n", 39 | " if(i.isupper()): \n", 40 | " decmsg+=chr((ord(i)-key-65)%26+65)\n", 41 | " else:\n", 42 | " decmsg+=chr((ord(i)-key-97)%26+97)\n", 43 | "\n", 44 | " print(\"Decrypted Message: \"+decmsg)\n", 45 | " \n", 46 | " " 47 | ] 48 | }, 49 | { 50 | "cell_type": "code", 51 | "execution_count": 18, 52 | "metadata": {}, 53 | "outputs": [ 54 | { 55 | "name": "stdout", 56 | "output_type": "stream", 57 | "text": [ 58 | "1513\n", 59 | "9457\n", 60 | "236\n", 61 | "5979\n", 62 | "8867\n", 63 | "1118\n", 64 | "8626\n", 65 | "3951\n", 66 | "2693\n", 67 | "3630\n" 68 | ] 69 | } 70 | ], 71 | "source": [ 72 | "import random\n", 73 | "for i in range(10):\n", 74 | " print(random.randint(1, 10000))" 75 | ] 76 | } 77 | ], 78 | "metadata": { 79 | "kernelspec": { 80 | "display_name": "Python 3", 81 | "language": "python", 82 | "name": "python3" 83 | }, 84 | "language_info": { 85 | "codemirror_mode": { 86 | "name": "ipython", 87 | "version": 3 88 | }, 89 | "file_extension": ".py", 90 | "mimetype": "text/x-python", 91 | "name": "python", 92 | "nbconvert_exporter": "python", 93 | "pygments_lexer": "ipython3", 94 | "version": "3.7.6" 95 | } 96 | }, 97 | "nbformat": 4, 98 | "nbformat_minor": 4 99 | } 100 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 MOHIT BHAT 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 | -------------------------------------------------------------------------------- /Learning Resources/LearningResources.md: -------------------------------------------------------------------------------- 1 | ### Learning Resources : 2 | 3 | [Hack This Site](https://www.hackthissite.org/) 4 | Hack This Site is a free and legal way to learn ethical hacking from scratch. It is one of the best training sites to learn hacking no matter if you are a beginner or advanced person. 5 | 6 | [Hack A Day](https://hackaday.com/) 7 | Hackaday is another best website to learn hacking. As their motto reads “Fresh Hacks Every Day”, this website delivers tutorials for powerful hacking attacks with the intent for students to understand the concepts better. 8 | 9 | [Break The Security](http://breakthesecurity.cysecurity.org/) 10 | If you are looking for anything specific to learn ethical hacking, you can directly search your query and get a post or tutorial covering that topic. 11 | 12 | [Hacking Loops](https://www.hackingloops.com/) 13 | Hacking Loops is an educational blog created with the purpose to help beginners to understand the framework of cybersecurity. 14 | 15 | [Cybrary](https://www.cybrary.it/) 16 | Cybrary includes a large-scale range of hacking and Cyber Security topics including: 17 | 1. Ethical Hacking 18 | 2. Penetration Testing 19 | 3. Cryptography 20 | 4. Forensics 21 | 5. Social Engineering 22 | 6. Post Exploitation 23 | 7. Malware Analysis and Reverse Engineering 24 | 25 | [Open SecurityTraining](https://www.youtube.com/user/OpenSecurityTraining/) 26 | This channel focuses on malware analysis, forensic database analysis, web browser attack, email origin obfuscation and much more. Some really interesting stuff here. 27 | 28 | [The Hacker News](https://thehackernews.com/) 29 | This website provides the latest and informational articles and news on data breaches and various incidents that take place over the world concerning the cyber security. It's important if incase someone goes off track and does malpractises. Viewers would also gain knowledge about various tactics and improve their skills! 30 | Another great website is [WeLiveSecurity](https://www.welivesecurity.com/). It provides with more cyber-info with better markings. 31 | 32 | [Hacker Noon](https://hackernoon.com/) is a great all-in-one website. It has blogs and articles on various topics: 33 | 1. Data Science 34 | 2. AI 35 | 3. Enterpreneurship 36 | 4. APIs 37 | 5. Almost all the languages 38 | 6. Cryptocurrency 39 | 7. Hacking 40 | These are just some highlighted topics out of a bunch. Enthusiasts can also learn web development, languages and a lot more. Added advantage is that Hacker Noon has partnership with Udemy so learning becomes integrated. It's a must visit! 41 | 42 | [KitPloit](https://www.kitploit.com/) is a place where you can learn and and practise working hacking tools! It has all the neccessary and known-to-many tools used while penetrating various OSs or devices like iOS or Android. Its a gold mine for beginners! 43 | -------------------------------------------------------------------------------- /Learning Resources/Links for Introduction to Cybersecurity.md: -------------------------------------------------------------------------------- 1 | *Youtube Resources*- 2 | 3 | 1 - An Introduction to Cybersecurity Careers - 4 | 2 - Get Started in Cybersecurity: Beginner Tips, Certifications and Career Paths - 5 | 3 - How it Works: Cybersecurity- 6 | 4 - Day in the Life of a Cybersecurity Student - 7 | 5 - Network Security - 8 | 6 - Chat with a Cybersecurity Recruiter - 9 | 7 - "AI & Machine Learning" Cybersecurity Conversation - 10 | 11 | Few Resources to Start off 12 | 13 | -> Complete these wargames which teach you how to crack each level, thereby increasing your knowlege on different aspects 14 | - 15 | -> Learn by following a structured pathway or guide your own learning. Deploy your own private hackable machines (no sharing) 16 | and use your skills in a real-world environment by completing guided, objective-based tasks. 17 | - 18 | -> 19 | 20 | Twitch Resource 21 | -> An ethical hacker who gives you a detailed explanation from everything thats required and shows how its done. 22 | - 23 | -------------------------------------------------------------------------------- /Learning Resources/Mobile Locator.md: -------------------------------------------------------------------------------- 1 | For locating mobile, Seeker is used for finding the geolocation of any mobile number with high accuracy. 2 | It's developed by thewhiteh4t. 3 | Seeker host phishing pages to get credentials. It host a fake page that requests user's location like many popular location based websites. 4 | Seeker hosts a fake website on In Built PHP Server and uses Serveo to generate a link which is forwarded to the target, website asks for Location Permission and if the target allows it, we can get : 5 | Longitude 6 | Latitude 7 | Accuracy 8 | Altitude - Not always available 9 | Direction - Only available if user is moving 10 | Speed - Only available if user is moving 11 | 12 | Its tested on 13 | Kali Linux 14 | BlackArch Linux 15 | Ubuntu 16 | Kali Nethunter 17 | Termux 18 | Parrot OS 19 | 20 | Installation 21 | Kali Linux / Ubuntu / Parrot OS 22 | git clone https://github.com/thewhiteh4t/seeker.git 23 | cd seeker/ 24 | chmod 777 install.sh 25 | ./install.sh 26 | BlackArch Linux 27 | pacman -S seeker 28 | Docker 29 | docker pull thewhiteh4t/seeker 30 | Termux 31 | git clone https://github.com/thewhiteh4t/seeker.git 32 | cd seeker/ 33 | chmod 777 termux_install.sh 34 | ./termux_install.sh 35 | Usage 36 | python3 seeker.py -h 37 | 38 | usage: seeker.py [-h] [-s SUBDOMAIN] 39 | 40 | optional arguments: 41 | -h, --help show this help message and exit 42 | -s SUBDOMAIN, --subdomain Subdomain Provide Subdomain for Serveo URL ( Optional ) 43 | -k KML, --kml KML Provide KML Filename ( Optional ) 44 | -t TUNNEL, --tunnel TUNNEL Specify Tunnel Mode [manual] 45 | 46 | # Example 47 | 48 | # SERVEO 49 | ######## 50 | python3 seeker.py 51 | 52 | # NGROK ETC. 53 | ############ 54 | 55 | # In First Terminal Start seeker in Manual mode like this 56 | python3 seeker.py -t manual 57 | 58 | # In Second Terminal Start Ngrok or any other tunnel service on port 8080 59 | ./ngrok http 8080 60 | 61 | #-----------------------------------# 62 | 63 | # Subdomain 64 | ########### 65 | python3 seeker.py --subdomain google 66 | python3 seeker.py --tunnel manual --subdomain zomato 67 | 68 | #-----------------------------------# 69 | 70 | # Docker Usage 71 | ############## 72 | 73 | # SERVEO 74 | ######## 75 | docker run -t --rm thewhiteh4t/seeker 76 | 77 | # NGROK 78 | ####### 79 | 80 | # Step 1 81 | docker network create ngroknet 82 | 83 | # Step 2 84 | docker run --rm -t --net ngroknet --name seeker thewhiteh4t/seeker python3 seeker.py -t manual 85 | 86 | # Step 3 87 | docker run --rm -t --net ngroknet --name ngrok wernight/ngrok ngrok http seeker:8080 -------------------------------------------------------------------------------- /Learning Resources/PenTest Methodologies.md: -------------------------------------------------------------------------------- 1 | 𝗣𝗲𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗠𝗲𝘁𝗵𝗼𝗱𝗼𝗹𝗼𝗴𝗶𝗲𝘀 - 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗲 𝗪𝗮𝗹𝗸𝘁𝗵𝗿𝗼𝘂𝗴𝗵 & 𝗧𝗼𝗼𝗹𝘀 2 | 3 | 1. Penetration Testing Framework - https://lnkd.in/f5cxT3Y 4 | 5 | 2. The Penetration Testing Execution Standard - https://lnkd.in/fJZJ8tR 6 | 7 | 3. The WASC Threat Classification - https://lnkd.in/fQ_x4BK 8 | 9 | 4. OWASP Top Ten Project - https://lnkd.in/fSJaPnW 10 | 11 | 5. Different Methodologies for Penetration Testing - https://lnkd.in/fxxJ8uM 12 | 13 | 6. Penetration Testing Methodology by 0daySecurity - http://tiny.cc/0dhjsd 14 | 15 | 7. Penetration Testing – Methodologies and Tools by edureka! - http://tiny.cc/ehfee 16 | 17 | 8. Penetration Testing: Tips & Tricks - http://tiny.cc/pttkq 18 | 19 | 9. A Complete Guide to the Phases of Penetration Testing - http://tiny.cc/jdfhe 20 | 21 | 10. Some of Best Pentesting Tools - http://tiny.cc/jthfj 22 | -------------------------------------------------------------------------------- /Learning Resources/PenTest Resources.md: -------------------------------------------------------------------------------- 1 | • 𝗔𝘄𝗲𝘀𝗼𝗺𝗲-𝗣𝗲𝗻𝘁𝗲𝘀𝘁 𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻: 2 | http://tiny.cc/hjdfhjer 3 | 4 | • 𝗣𝗘𝗡𝗧𝗘𝗦𝗧𝗜𝗡𝗚-𝗕𝗜𝗕𝗟𝗘 [𝗖𝗼𝗹𝗹𝗲𝗰𝘁𝗶𝗼𝗻 𝗼𝗳 𝗩𝗮𝗿𝗶𝗼𝘂𝘀 𝗣𝗲𝗻𝘁𝗲𝘀𝘁 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 & 𝗧𝗼𝗼𝗹𝘀] [𝟭𝟱𝟬𝟬+ 𝗔𝗿𝘁𝗶𝗰𝗹𝗲𝘀] 5 | http://tiny.cc/hr4Io 6 | 7 | • 𝗣𝗲𝗻𝘁𝗲𝘀𝘁-𝘄𝗶𝗸𝗶 8 | http://tiny.cc/56oO9 9 | 10 | • 𝗣𝗲𝗻𝗲𝘁𝗿𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 - 𝗦𝗲𝘁𝘁𝗶𝗻𝗴 𝗨𝗽 𝘁𝗵𝗲 𝗟𝗮𝗯 𝗘𝗻𝘃𝗶𝗿𝗼𝗻𝗺𝗲𝗻𝘁 11 | http://tiny.cc/jf57Ll 12 | 13 | • 𝗣𝗘𝗡𝗘𝗧𝗥𝗔𝗧𝗜𝗢𝗡 𝗧𝗘𝗦𝗧𝗜𝗡𝗚 𝗣𝗥𝗔𝗖𝗧𝗜𝗖𝗘 𝗟𝗔𝗕 [𝗠𝗜𝗡𝗗𝗠𝗔𝗣]: 14 | http://tiny.cc/mind-map 15 | 16 | • 𝗣𝗲𝗻𝘁𝗲𝘀𝘁𝗶𝗻𝗴 𝗖𝗵𝗲𝗮𝘁𝘀𝗵𝗲𝗲𝘁: 17 | http://tiny.cc/ctsht 18 | 19 | • 𝗣𝗲𝗻𝗲𝘁𝗿𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗖𝗼𝗺𝗽𝗹𝗲𝘁𝗲 𝗧𝗼𝗼𝗹𝘀 𝗟𝗶𝘀𝘁 [𝟮𝟯𝟬𝟬+ 𝗧𝗼𝗼𝗹𝘀]: 20 | http://tiny.cc/jdf7ht 21 | 22 | • 𝗪𝗲𝗯 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗣𝗲𝗻𝗲𝘁𝗿𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗣𝗵𝗮𝘀𝗲𝘀 - http://tiny.cc/hjd66 23 | 24 | • 𝗢𝗪𝗔𝗦𝗣 𝗧𝗼𝗽 𝟭𝟬: 𝗥𝗲𝗮𝗹-𝗪𝗼𝗿𝗹𝗱 𝗘𝘅𝗮𝗺𝗽𝗹𝗲𝘀 (𝗣𝗮𝗿𝘁 𝟭) - http://tiny.cc/hjdf8 25 | 26 | • 𝗢𝗪𝗔𝗦𝗣 𝗧𝗼𝗽 𝟭𝟬: 𝗥𝗲𝗮𝗹-𝗪𝗼𝗿𝗹𝗱 𝗘𝘅𝗮𝗺𝗽𝗹𝗲𝘀 (𝗣𝗮𝗿𝘁 𝟮) - http://tiny.cc/b4L 27 | 28 | • 𝗔𝘄𝗲𝘀𝗼𝗺𝗲 𝗣𝗲𝗻𝗲𝘁𝗿𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 - http://tiny.cc/fd54re 29 | 30 | • 𝗪𝗲𝗯 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 - http://tiny.cc/n8o 31 | 32 | • 𝗪𝗲𝗯 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 𝗧𝗼𝗼𝗹𝘀 & 𝗥𝗲𝘀𝗼𝘂𝗿𝗰𝗲𝘀 𝗳𝗼𝗿 𝗛𝗮𝗰𝗸𝗲𝗿𝘀 𝗮𝗻𝗱 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 𝗣𝗿𝗼𝗳𝗲𝘀𝘀𝗶𝗼𝗻𝗮𝗹𝘀 - http://tiny.cc/dsb5g8 33 | 34 | • 𝗪𝗲𝗯 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 𝗚𝘂𝗶𝗱𝗲 𝗯𝘆 𝗥𝗮𝗻𝗼𝗿𝗲𝘅 - http://tiny.cc/fsdh54545 35 | 36 | • 𝗣𝗲𝗻𝗲𝘁𝗿𝗮𝘁𝗶𝗼𝗻 𝗧𝗲𝘀𝘁𝗶𝗻𝗴: 𝗦𝘁𝗲𝗽-𝗯𝘆-𝗦𝘁𝗲𝗽 𝗚𝘂𝗶𝗱𝗲, 𝗦𝘁𝗮𝗴𝗲𝘀, 𝗠𝗲𝘁𝗵𝗼𝗱𝘀 𝗮𝗻𝗱 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 - http://tiny.cc/hreq0i 37 | 38 | • 𝗕𝗲𝘀𝘁 𝗣𝗿𝗮𝗰𝘁𝗶𝗰𝗲𝘀 𝗳𝗼𝗿 𝗪𝗲𝗯 𝗔𝗽𝗽𝗹𝗶𝗰𝗮𝘁𝗶𝗼𝗻 𝗦𝗲𝗰𝘂𝗿𝗶𝘁𝘆 𝗧𝗲𝘀𝘁𝗶𝗻𝗴 - http://tiny.cc/1lIldio0 -------------------------------------------------------------------------------- /Learning Resources/pdfs/Black Hat Python.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcse/Security_Hacking_Scripts/7deea3703af3c347f6faaa3d6d87d8dd5c496465/Learning Resources/pdfs/Black Hat Python.pdf -------------------------------------------------------------------------------- /Learning Resources/pdfs/Ehthical hacking book tutorials point.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcse/Security_Hacking_Scripts/7deea3703af3c347f6faaa3d6d87d8dd5c496465/Learning Resources/pdfs/Ehthical hacking book tutorials point.pdf -------------------------------------------------------------------------------- /Learning Resources/pdfs/Ethical Hacking and Penetration Testing Guide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcse/Security_Hacking_Scripts/7deea3703af3c347f6faaa3d6d87d8dd5c496465/Learning Resources/pdfs/Ethical Hacking and Penetration Testing Guide.pdf -------------------------------------------------------------------------------- /Learning Resources/pdfs/The Hacker Playbook 2 - Practical Guide To Penetration Testing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcse/Security_Hacking_Scripts/7deea3703af3c347f6faaa3d6d87d8dd5c496465/Learning Resources/pdfs/The Hacker Playbook 2 - Practical Guide To Penetration Testing.pdf -------------------------------------------------------------------------------- /Learning Resources/pdfs/[Bookflare.net] - Cryptors Hacker Manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcse/Security_Hacking_Scripts/7deea3703af3c347f6faaa3d6d87d8dd5c496465/Learning Resources/pdfs/[Bookflare.net] - Cryptors Hacker Manual.pdf -------------------------------------------------------------------------------- /Projects/.idea/Security_Hacking_Scripts.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Projects/.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /Projects/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Projects/.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Projects/.idea/workspace.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 12 | 13 | 15 | 16 | 17 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1603046981675 31 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Wassup chat app 7 | 8 | 9 | 10 | 11 |
12 |
13 | 14 |

Wassup

15 |
16 |
17 |
18 | NAME:   Key: 19 | 20 |
21 |
22 |
23 |
24 | 30 |
31 |
32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chatwithcrypto", 3 | "version": "1.0.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "dev": "nodemon server", 8 | "serve": "node server" 9 | }, 10 | "keywords": [], 11 | "author": "", 12 | "license": "ISC", 13 | "dependencies": { 14 | "express": "^4.17.1", 15 | "socket.io": "^2.3.0" 16 | }, 17 | "devDependencies": { 18 | "nodemon": "^2.0.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/plan.txt: -------------------------------------------------------------------------------- 1 | TODO: 2 | 3 | [+] Create NPM project 4 | 5 | [+] Create Index, Css, Js files 6 | 7 | [+] Install dependancies. express, nodemon(dev dep.) 8 | 9 | [+] Create a express server (server.js) 10 | 11 | [+] do frontend part 12 | 13 | [+] Install socket.io, Setup socket.io in server.js and client client.js 14 | 15 | [+] Client send message logic in client.js 16 | 17 | [+] Recieve message on server and broadcast to all clients 18 | 19 | [+] Recieve message on client and display it. scrollToBottom etc... 20 | -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/public/client.js: -------------------------------------------------------------------------------- 1 | const socket = io(); 2 | let name; 3 | let key; 4 | let textarea = document.querySelector("#textarea"); 5 | let messageArea = document.querySelector(".message__area"); 6 | do { 7 | name = prompt("Please enter your name: "); 8 | do { 9 | key = prompt("Please enter your encryption Key: ").toUpperCase(); 10 | } while (!key); 11 | } while (!name); 12 | 13 | document.getElementById("nameid").innerHTML = name; 14 | document.getElementById("keyid").innerHTML = key; 15 | 16 | textarea.addEventListener("keyup", (e) => { 17 | if (e.key === "Enter") { 18 | sendMessage(e.target.value.toUpperCase().trim()); 19 | } 20 | }); 21 | 22 | function sendMessage(message) { 23 | console.log(message); 24 | let msg = { 25 | user: name, 26 | message: message, 27 | }; 28 | // Append 29 | appendMessage(msg, "outgoing"); 30 | textarea.value = ""; 31 | scrollToBottom(); 32 | 33 | // Send to server 34 | msg.message = encrypt(msg.message, key); 35 | socket.emit("message", msg); 36 | } 37 | 38 | function appendMessage(msg, type) { 39 | let mainDiv = document.createElement("div"); 40 | let className = type; 41 | mainDiv.classList.add(className, "message"); 42 | let markup = ` 43 |

${msg.user}

44 |

${msg.message}

45 | `; 46 | mainDiv.innerHTML = markup; 47 | messageArea.appendChild(mainDiv); 48 | } 49 | 50 | // Recieve messages 51 | socket.on("message", (msg) => { 52 | msg.message = decrypt(msg.message, key); 53 | appendMessage(msg, "incoming"); 54 | scrollToBottom(); 55 | }); 56 | 57 | function scrollToBottom() { 58 | messageArea.scrollTop = messageArea.scrollHeight; 59 | } 60 | 61 | //*******************ENCRYPTION ALGOS***************** */ 62 | function convertKey(text, keyy) { 63 | var nkey = ""; 64 | var l = keyy.length; 65 | for (var i = 0; i < text.length; i++) { 66 | nkey += keyy[i % l]; 67 | } 68 | 69 | return nkey; 70 | } 71 | function encrypt(text, nkey) { 72 | nkey = convertKey(text, nkey); 73 | var enctxt = ""; 74 | for (var i = 0; i < text.length; i++) { 75 | if (text[i] == " ") enctxt += " "; 76 | else 77 | enctxt += String.fromCharCode( 78 | ((text[i].charCodeAt(0) + nkey[i].charCodeAt(0)) % 26) + 65 79 | ); 80 | } 81 | return enctxt; 82 | } 83 | 84 | function decrypt(text, nkey) { 85 | nkey = convertKey(text, nkey); 86 | var dectxt = ""; 87 | for (var i = 0; i < text.length; i++) { 88 | if (text[i] == " " && i < text.length) dectxt += " "; 89 | else 90 | dectxt += String.fromCharCode( 91 | ((text[i].charCodeAt(0) - nkey[i].charCodeAt(0) + 26) % 26) + 65 92 | ); 93 | } 94 | return dectxt; 95 | } 96 | -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/public/style.css: -------------------------------------------------------------------------------- 1 | @import url('https://fonts.googleapis.com/css2?family=Roboto&display=swap'); 2 | * { 3 | padding: 0; 4 | margin: 0; 5 | box-sizing: border-box; 6 | } 7 | 8 | body { 9 | display: flex; 10 | align-items: center; 11 | justify-content: center; 12 | min-height: 100vh; 13 | background: #F8F8F8; 14 | font-family: 'Roboto', sans-serif; 15 | } 16 | section.chat__section { 17 | width: 800px; 18 | max-width: 90%; 19 | background: #fff; 20 | box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05); 21 | } 22 | .brand { 23 | padding: 20px; 24 | background: #f1f1f1; 25 | display: flex; 26 | align-items: center; 27 | } 28 | .brand h1 { 29 | text-transform: uppercase; 30 | font-size: 20px; 31 | color: #444; 32 | margin-left: 10px; 33 | } 34 | .message__area{ 35 | height: 500px; 36 | padding: 16px; 37 | display: flex; 38 | flex-direction: column; 39 | overflow-y: auto; 40 | padding-top: 40px; 41 | } 42 | textarea { 43 | width: 100%; 44 | border: none; 45 | padding: 20px; 46 | font-size: 16px; 47 | outline: none; 48 | background: #FBFBFB; 49 | } 50 | 51 | .message { 52 | padding: 20px; 53 | border-radius: 4px; 54 | margin-bottom: 40px; 55 | max-width: 300px; 56 | position: relative; 57 | } 58 | .incoming { 59 | background: #8F8BE8; 60 | color: #fff; 61 | } 62 | .outgoing { 63 | background: #e9eafd; 64 | color: #787986; 65 | margin-left: auto; 66 | } 67 | .message h4 { 68 | position: absolute; 69 | top: -20px; 70 | left: 0; 71 | color: #333; 72 | font-size: 14px; 73 | } -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/public/wassup.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mbcse/Security_Hacking_Scripts/7deea3703af3c347f6faaa3d6d87d8dd5c496465/Projects/EncryptedChatUsingBasicCypherAlgo/public/wassup.png -------------------------------------------------------------------------------- /Projects/EncryptedChatUsingBasicCypherAlgo/server.js: -------------------------------------------------------------------------------- 1 | const express = require("express"); 2 | const app = express(); 3 | const http = require("http").createServer(app); 4 | 5 | const PORT = process.env.PORT || 3000; 6 | 7 | http.listen(PORT, () => { 8 | console.log(`Listening on port ${PORT}`); 9 | }); 10 | 11 | app.use(express.static(__dirname + "/public")); 12 | 13 | app.get("/", (req, res) => { 14 | res.sendFile(__dirname + "/index.html"); 15 | }); 16 | 17 | // Socket 18 | const io = require("socket.io")(http); 19 | 20 | io.on("connection", (socket) => { 21 | console.log("Connected..."); 22 | socket.on("message", (msg) => { 23 | console.log(msg); 24 | socket.broadcast.emit("message", msg); 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Security_Hacking_Scripts 2 | 3 | **Encryption Algo Scripts, Ethical Hacking Scripts, Cybersecurity-Ethical Hacking Learning Resources, and Security-Based Projects** 4 | 5 | [![License](https://img.shields.io/github/license/mbcse/Security_Hacking_Scripts?color=green&style=flat-square)](https://github.com/mbcse/Security_Hacking_Scripts/blob/master/LICENSE) 6 | [![Hacktoberfest](https://img.shields.io/static/v1?label=Hacktoberfest&message=2020&color=blueviolet)](https://hacktoberfest.digitalocean.com/) 7 | 8 | [![GitHub forks](https://img.shields.io/github/forks/mbcse/Security_Hacking_Scripts?style=flat-square)](https://github.com/mbcse/Security_Hacking_Scripts/network/members) 9 | [![GitHub stars](https://img.shields.io/github/stars/mbcse/Security_Hacking_Scripts?style=flat-square)](https://github.com/mbcse/Security_Hacking_Scripts/stargazers) 10 | [![GitHub issues](https://img.shields.io/github/issues/mbcse/Security_Hacking_Scripts?color=blue&style=flat-square)](https://github.com/mbcse/Security_Hacking_Scripts/issues?q=is%3Aopen+is%3Aissue) 11 | [![GitHub pull requests](https://img.shields.io/github/issues-pr/cdnjs/cdnjs?style=flat-square)](https://github.com/mbcse/Security_Hacking_Scripts/pulls?q=is%3Aopen+is%3Apr) 12 | 13 | 14 | 15 | 16 | [![forthebadge](https://forthebadge.com/images/badges/built-by-developers.svg)](https://forthebadge.com) 17 | [![forthebadge](https://forthebadge.com/images/badges/built-with-love.svg)](https://forthebadge.com) 18 | [![forthebadge](https://forthebadge.com/images/badges/built-with-swag.svg)](https://forthebadge.com) 19 | 20 | # 📌About 21 | 22 | This Repository is to curate the scripts used for hacking as well as for providing security to applications. It can be in form of some kind of learning material, scripts, projects, simulations scripts, encryption algorithms, etc. 23 | 24 | # 💻Languages 25 | 26 | - C++ 27 | - Python 28 | - NodeJs 29 | - Go 30 | - Php 31 | - Javascript 32 | - Java 33 | - Ruby 34 | - Django 35 | 36 | # 💥 How to Contribute? 37 | 38 | ## 1. Fork this repository 39 | 40 | Fork this repository by clicking on the fork button on the top of this page. 41 | This will create a copy of this repository in your account. 42 | 43 | --- 44 | 45 | ## 2. Clone the repository 46 | 47 | Now clone the forked repository to your machine. Go to your GitHub account, open the forked repository, click on the clone button and then click the _copy to clipboard_ icon. 48 | Now let's bring the cloned repository to your local machine. 49 | `git clone ` 50 | For example: 51 | ` git clone https://github.com/mbcse/Security_Hacking_Scripts.git` 52 | 53 | --- 54 | 55 | ## 3. Move inside the repository 56 | 57 | Since you want to change the files inside, first let's move to the folder correctly. Use the following command on the terminal: 58 | `cd Security_Hacking_Scripts` 59 | 60 | --- 61 | 62 | ## 4. Make a new branch 63 | 64 | Since now you're about to make your changes to the project, it's always a better idea to make a new branch. Run the following command: 65 | 66 | `git checkout -b ` 67 | For example: 68 | `git checkout -b new_branch` 69 | 70 | --- 71 | 72 | ## 5. Make the required changes 73 | 74 | You can Contribute By adding 75 | 76 | - Encryption Algorithms Script in any language 77 | - Adding Security-Based Projects 78 | - Adding Ethical Hacking Scripts(DDOS etc) 79 | - Adding Cybersecurity and Ethical Hacking Learning Resources(ppt's, readme's, docs, links, etc) 80 | - Making a website for this Project 81 | - Improving/Documenting The Readme 82 | - Checking for any typing and grammatical errors 83 | 84 | --- 85 | 86 | ## 6. Commit all your changes 87 | 88 | It's finally that time when you commit your changes and leave a beautiful commit message behind. You can run the following commands: 89 | 90 | `git add .` 91 | `git commit -m ""` 92 | For example: 93 | `git commit -m "Added a script"` 94 | 95 | Finally, push your changes to Github: 96 | To do so run the following command: 97 | 98 | `git push origin ` 99 | For example: 100 | `git push origin branch_name` 101 | 102 | --- 103 | 104 | ## 7. Hit us a pull request 105 | 106 | If you go to your repository on GitHub, you'll see a Compare & pull request button. Click on that button. 107 | Now submit the pull request. Leave a custom message if you want. 108 | 109 | --- 110 | 111 | 112 | --------------------------------------------------------------------------------