├── cheatsheet.pdf ├── requirement.txt ├── README.md └── dagger.py /cheatsheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AdityaSec/dagger/HEAD/cheatsheet.pdf -------------------------------------------------------------------------------- /requirement.txt: -------------------------------------------------------------------------------- 1 | pyfiglet 2 | clint 3 | requests 4 | gmpy2 5 | PyCrypto 6 | bs4 7 | sympy 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # dagger-ctf 2 | A Crypto-CTF Assistant For Saving You Time. 3 | 4 | 5 | ## Prerequisite 6 | ``` 7 | git clone https://github.com/AdityaSec/dagger 8 | cd dagger 9 | sudo apt install libmpc-dev python3 python3-pip 10 | pip3 install -r requirement.txt 11 | ``` 12 | ## Usage 13 | ``` 14 | python3 dagger.py 15 | ``` 16 | Checkout cheatsheet.pdf , if you are stuck in identifying type of cipher. 17 | -------------------------------------------------------------------------------- /dagger.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | import requests 4 | import re 5 | import gmpy2 6 | import binascii 7 | import argparse 8 | import os 9 | import sys 10 | import base64 11 | import time 12 | import struct 13 | import sympy 14 | import Crypto.PublicKey.RSA as RSA 15 | from clint.textui import puts, colored, indent 16 | from Crypto.Util.number import * 17 | from bs4 import BeautifulSoup 18 | 19 | def b32(enc): 20 | cipher="".join(enc.split()) 21 | cipher=base64.b32decode(cipher) 22 | return cipher.decode('UTF-8') 23 | 24 | def b64(enc): 25 | cipher="".join(enc.split()) 26 | result=None 27 | for i in range(0,20): 28 | try: 29 | cipher=base64.b64decode(cipher + "===").decode('UTF-8') 30 | except: 31 | break 32 | return cipher 33 | 34 | def b85(enc): 35 | cipher=enc.encode('UTF-8') 36 | dec=base64.a85decode(cipher) 37 | return dec.decode('UTF-8') 38 | 39 | 40 | def hextotext(enc): 41 | if enc.startswith('0x'): 42 | hex_string = enc[2:] 43 | else: 44 | hex_string=enc 45 | bytes_object = bytes.fromhex(hex_string) 46 | ascii_string = bytes_object.decode("ASCII") 47 | return ascii_string 48 | 49 | def dectotext(enc): 50 | string='' 51 | deci=enc.split() 52 | for i in deci: 53 | string+=chr(int(i)) 54 | return string 55 | 56 | def octtotext(enc): 57 | string='' 58 | oc=enc.split() 59 | for c in oc: 60 | string+=chr(int(c,8)) 61 | return string 62 | 63 | def bintotext(enc): 64 | bword=[enc[i:i+8] for i in range(0,len(enc),8)] 65 | string='' 66 | for ch in bword: 67 | a=int(ch,2) 68 | a=chr(a) 69 | string+=a 70 | return string 71 | 72 | 73 | def cuberootrsa(n,e,c): 74 | #enc str type 75 | if e!=3: 76 | print("\033[1;31;40m [+] Value of e should be 3 in Cube Root RSA\n") 77 | def cuberoot(x): 78 | c,c1=None,2 79 | while c!=c1: 80 | c=c1 81 | c3=c**3 82 | d=(2*c3+x) 83 | c1=(c*(c3+2*x)+d//2)//d 84 | return c 85 | cn=cuberoot(n) 86 | cc=cuberoot(c) 87 | if cc < cn : 88 | flag=repr(binascii.unhexlify(hex(cc)[2:])) 89 | return flag[2:] 90 | else: 91 | print("\033[1;31;40m [+] Error. Cube Root Of C is Not Less Than Cube Root Of N\n") 92 | 93 | def twinprime(n1,n2,c,e): 94 | def crack(n): 95 | url_1='http://factordb.com/index.php?query=%i' 96 | url_2 ='http://factordb.com/index.php?id=%s' 97 | s = requests.Session() 98 | r = s.get(url_1 %n, verify=False) 99 | regex = re.compile("index\.php\?id\=([0-9]+)", re.IGNORECASE) 100 | ids = regex.findall(r.text) 101 | factor=[] 102 | regex = re.compile("value=\"([0-9\^\-]+)\"", re.IGNORECASE) 103 | for i in range(1,len(ids)): 104 | fact_id=ids[i] 105 | factr=s.get(url_2 % fact_id, verify=False) 106 | key=regex.findall(factr.text)[0] 107 | factor.append(key) 108 | return factor 109 | 110 | npq1=crack(n1) 111 | p1=int(npq1[0]) 112 | q1=int(npq1[1]) 113 | npq2=crack(n2) 114 | p2=int(npq2[0]) 115 | q2=int(npq2[1]) 116 | d1 = inverse(e, (p1-1)*(q1-1)) 117 | d2 = inverse(e, (p2-1)*(q2-1)) 118 | pkey2 = RSA.construct((n2, e, d2, p2, q2)) 119 | pkey1 = RSA.construct((n1, e, d1, p1, q1)) 120 | 121 | m2 = pkey2.decrypt(c) 122 | m1 = pkey1.decrypt(m2) 123 | try: 124 | return long_to_bytes(m1).decode('UTF-8') 125 | except: 126 | m = long_to_bytes(m1) 127 | end = m.index(0x7d) 128 | return m[:end+1].decode('UTF-8') 129 | 130 | 131 | def weinerrsa(n,e,c): 132 | def r2c(x,y): 133 | a=x//y 134 | pquotient=[a] 135 | while a*y!=x: 136 | x,y=y,x-a*y 137 | a=x//y 138 | pquotient.append(a) 139 | return pquotient 140 | def cfc(frac): 141 | convs=[]; 142 | for i in range(len(frac)): 143 | convs.append(c2r(frac[0:i])) 144 | return convs 145 | def c2r(frac): 146 | if len(frac)==0: 147 | return (0,1) 148 | num=frac[-1] 149 | denom=1 150 | for _ in range(-2,-len(frac)-1, -1): 151 | num,denom= frac[_]*num+denom, num 152 | return(num,denom) 153 | def egcd(a,b): 154 | if a==0: 155 | return (b,0,1) 156 | g,x,y=egcd(b%a,a) 157 | return (g, y - (b//a)*x, x) 158 | def modinv(a,m): 159 | g,x,_=egcd(a,m) 160 | return (x+m)%m 161 | def isqrt(n): 162 | x=n 163 | y=(x+1)//2 164 | while y=0: 177 | sq=isqrt(D) 178 | if sq*sq==D and (s+sq)%2==0: return d 179 | d=crack(e,n) 180 | m=pow(c,d,n) 181 | flag=repr(binascii.unhexlify(hex(m)[2:])) 182 | return flag[2:] 183 | 184 | 185 | def commonmodulo(n,e1,e2,c1,c2): 186 | def egcd(a, b): 187 | if (a == 0): 188 | return (b, 0, 1) 189 | else: 190 | g, y, x = egcd(b % a, a) 191 | return (g, x - (b // a) * y, y) 192 | 193 | # Calculates a^{b} mod n when b is negative 194 | def neg_pow(a, b, n): 195 | assert b < 0 196 | assert GCD(a, n) == 1 197 | res = int(gmpy2.invert(a, n)) 198 | res = pow(res, b*(-1), n) 199 | return res 200 | g, a, b = egcd(e1, e2) 201 | if a < 0: 202 | c1 = neg_pow(c1, a, n) 203 | else: 204 | c1 = pow(c1, a, n) 205 | if b < 0: 206 | c2 = neg_pow(c2, b, n) 207 | else: 208 | c2 = pow(c2, b, n) 209 | ct = c1*c2 % n 210 | m = int(gmpy2.iroot(ct, g)[0]) 211 | return long_to_bytes(m).decode('UTF-8') 212 | 213 | def classicrsa(n,e,c): 214 | url_1='http://factordb.com/index.php?query=%i' 215 | url_2 ='http://factordb.com/index.php?id=%s' 216 | s = requests.Session() 217 | r = s.get(url_1 %n, verify=False) 218 | regex = re.compile("index\.php\?id\=([0-9]+)", re.IGNORECASE) 219 | ids = regex.findall(r.text) 220 | factor=[] 221 | regex = re.compile("value=\"([0-9\^\-]+)\"", re.IGNORECASE) 222 | for i in range(1,len(ids)): 223 | fact_id=ids[i] 224 | factr=s.get(url_2 % fact_id, verify=False) 225 | key=regex.findall(factr.text)[0] 226 | factor.append(key) 227 | #from here the will be passed as list and len of list will tell 228 | if len(factor) >2 : 229 | print("\033[1;32;40m","[+] Multiple Prime Factors Found.\n") 230 | print("\033[1;32;40m","[+] Multi Prime Attack.\n") 231 | phi=1 232 | for i in range(0,len(factor)): 233 | phi=phi*(int(factor[i])-1) 234 | d = inverse( e, phi ) 235 | m = pow( c, d, n ) 236 | flag=repr(binascii.unhexlify(hex(m)[2:])) 237 | return flag[2:] 238 | 239 | def crt(p,q,dp,dq,c): 240 | p=p 241 | q=q 242 | dp=dp 243 | dq=dq 244 | c=c 245 | def egcd(a, b): 246 | if a == 0: 247 | return (b, 0, 1) 248 | else: 249 | g, x, y = egcd(b % a, a) 250 | return (g, y - (b // a) * x, x) 251 | 252 | def decryptRSA(p,q,e,ct): 253 | # compute n 254 | n = p * q 255 | phi = (p - 1) * (q - 1) 256 | gcd, a, b = egcd(e, phi) 257 | d = a 258 | pt = pow(ct, d, n) 259 | return pt 260 | 261 | def mulinv(b, n): 262 | g, x, _ = egcd(b, n) 263 | if g == 1: 264 | return x % n 265 | Qinv = mulinv(q,p) 266 | m1 = pow(c, dp, p) 267 | m2 = pow(c, dq, q) 268 | h = (Qinv * (m1 - m2)) % p 269 | m = m2 + (h*q) 270 | flag= repr(binascii.unhexlify(hex(m)[2:])) 271 | return flag[2:-1] 272 | 273 | def rot47(enc): 274 | decode = [] 275 | data=enc 276 | for i in range(len(data)): 277 | encoded = ord(data[i]) 278 | if encoded >= 33 and encoded <= 126: 279 | decode.append(chr(33 + ((encoded + 14) % 94))) 280 | else: 281 | decode.append(data[i]) 282 | return ''.join(decode) 283 | 284 | def rot(enc,key): 285 | dec="" 286 | for word in enc: 287 | if(word.isupper()): 288 | dec = dec + chr((ord(word) - key - 65) % 26 + 65) 289 | elif(word.islower()): 290 | dec = dec + chr((ord(word) - key - 97) % 26 + 97) 291 | else: 292 | dec += word 293 | return dec 294 | 295 | def morse(enc): 296 | cipher = enc.lower() 297 | pool = {'.-':'a','..--.-':'_','-...':'b','-.-.':'c','-..':'d','.':'e','..-.':'f','--.':'g','....':'h','..':'i','.---':'j','-.-':'k','.-..':'l','--':'m','-.':'n','---':'o','.--.':'p','--.-':'q','.-.':'r','...':'s','-':'t','..-':'u','...-':'v','.--':'w','-..-':'x','-.--':'y','--..':'z','.----':'1','..---':'2','...--':'3','....-':'4','.....':'5','-....':'6','--...':'7','---..':'8','----.':'9','-----':'0','--..--':',','.-.-.-':'.','..--..':'?','-..-.':'/','-....-':'-','-.--.':'(','-.--.-':')','.......':' ','/': ' '} 298 | plain="" 299 | text="" 300 | prev="" 301 | for word in cipher: 302 | if(word != ' '): 303 | text += word 304 | prev=text 305 | else: 306 | plain += pool[text] 307 | text = "" 308 | plain+=pool[prev] 309 | print("\033[1;33;40m","[+] Place { } Manually If Required") 310 | return plain 311 | 312 | def dna(enc): 313 | cipher=enc 314 | #Three Character Block 315 | print("\033[1;33;40m","[+] Doing Standard Decoding") 316 | mapp={ 317 | 'AAA':'a', 'AAC':'b', 'AAG':'c', 'AAT':'d', 318 | 'ACA':'e', 'ACC':'f', 'ACG':'g', 'ACT':'h', 319 | 'AGA':'i', 'AGC':'j', 'AGG':'k', 'AGT':'l', 320 | 'ATA':'m', 'ATC':'n', 'ATG':'o', 'ATT':'p', 321 | 'CAA':'q', 'CAC':'r', 'CAG':'s', 'CAT':'t', 322 | 'CCA':'u', 'CCC':'v', 'CCG':'w', 'CCT':'x', 323 | 'CGA':'y', 'CGC':'z', 'CGG':'A', 'CGT':'B', 324 | 'CTA':'C', 'CTC':'D', 'CTG':'E', 'CTT':'F', 325 | 'GAA':'G', 'GAC':'H', 'GAG':'I', 'GAT':'J', 326 | 'GCA':'K', 'GCC':'L', 'GCG':'M', 'GCT':'N', 327 | 'GGA':'O', 'GGC':'P', 'GGG':'Q', 'GGT':'R', 328 | 'GTA':'S', 'GTC':'T', 'GTG':'U', 'GTT':'V', 329 | 'TAA':'W', 'TAC':'X', 'TAG':'Y', 'TAT':'Z', 330 | 'TCA':'1', 'TCC':'2', 'TCG':'3', 'TCT':'4', 331 | 'TGA':'5', 'TGC':'6', 'TGG':'7', 'TGT':'8', 332 | 'TTA':'9', 'TTC':'0', 'TTG':' ', 'TTT':'.', 333 | } 334 | dec=[] 335 | for x in range(0,len(enc),3): 336 | piece=enc[x:x+3] 337 | dec.append(mapp[piece]) 338 | return ''.join(dec) 339 | 340 | def brainfuck(enc): 341 | def evalu(code): 342 | dec='' 343 | code = cleanup(list(code)) 344 | bracemap = buildbracemap(code) 345 | cell, cdp, clp = [0], 0, 0 346 | while cdp < len(code): 347 | command = code[cdp] 348 | if command == ">": 349 | clp += 1 350 | if clp == len(cell): cell.append(0) 351 | if command == "<": 352 | clp = 0 if clp <= 0 else clp - 1 353 | if command == "+": 354 | cell[clp] = cell[clp] + 1 if cell[clp] < 255 else 0 355 | if command == "-": 356 | cell[clp] = cell[clp] - 1 if cell[clp] > 0 else 255 357 | if command == "[" and cell[clp] == 0: 358 | cdp = bracemap[cdp] 359 | if command == "]" and cell[clp] != 0: 360 | cdp = bracemap[cdp] 361 | if command == ".": 362 | dec+=chr(cell[clp]) 363 | if command == ",": 364 | cell[clp] = ord(getch.getch()) 365 | cdp += 1 366 | print("\033[1;32;40m","[+] Found:",dec) 367 | def cleanup(code): 368 | return ''.join(filter(lambda x: x in ['.', ',', '[', ']', '<', '>', '+', '-'], code)) 369 | def buildbracemap(code): 370 | temp_bracestack, bracemap = [], {} 371 | for position, command in enumerate(code): 372 | if command == "[": temp_bracestack.append(position) 373 | if command == "]": 374 | start = temp_bracestack.pop() 375 | bracemap[start] = position 376 | bracemap[position] = start 377 | return bracemap 378 | evalu(enc) 379 | 380 | 381 | def bacon26(enc): 382 | lookup = {'A':'aaaaa', 'B':'aaaab', 'C':'aaaba', 'D':'aaabb', 'E':'aabaa', 383 | 'F':'aabab', 'G':'aabba', 'H':'aabbb', 'I':'abaaa', 'J':'abaab', 384 | 'K':'ababa', 'L':'ababb', 'M':'abbaa', 'N':'abbab', 'O':'abbba', 385 | 'P':'abbbb', 'Q':'baaaa', 'R':'baaab', 'S':'baaba', 'T':'baabb', 386 | 'U':'babaa', 'V':'babab', 'W':'babba', 'X':'babbb', 'Y':'bbaaa', 'Z':'bbaab'} 387 | decipher = '' 388 | i = 0 389 | enc=enc.lower() 390 | while True : 391 | if(i < len(enc)-4): 392 | substr = enc[i:i + 5] 393 | if(substr[0] != ' '): 394 | decipher += list(lookup.keys())[list(lookup.values()).index(substr)] 395 | i += 5 396 | else: 397 | decipher += ' ' 398 | i += 1 399 | else: 400 | break # emulating a do-while loop 401 | return decipher 402 | 403 | def bacon24(enc): 404 | lookup = {'A':'aaaaa', 'B':'aaaab', 'C':'aaaba', 'D':'aaabb', 'E':'aabaa', 405 | 'F':'aabab', 'G':'aabba', 'H':'aabbb', 'I':'abaaa', 'K':'abaab', 406 | 'L':'ababa', 'M':'ababb', 'N':'abbaa', 'O':'abbab', 'P':'abbba', 407 | 'Q':'abbbb', 'R':'baaaa', 'S':'baaab', 'T':'baaba', 'U':'baabb', 408 | 'W':'babaa', 'X':'babab', 'Y':'babba', 'Z':'babbb'} 409 | decipher = '' 410 | i = 0 411 | enc=enc.lower() 412 | while True : 413 | if(i < len(enc)-4): 414 | substr = enc[i:i + 5] 415 | if(substr[0] != ' '): 416 | decipher += list(lookup.keys())[list(lookup.values()).index(substr)] 417 | i += 5 418 | else: 419 | decipher += ' ' 420 | i += 1 421 | else: 422 | break # emulating a do-while loop 423 | return decipher 424 | 425 | def vignereMatrix(r,c): 426 | 427 | alpha ={'A':0,'B':1,'C':2,'D':3,'E':4,'F':5,'G':6,'H':7,'I':8,'J':9,'K':10,'L':11,'M':12,'N':13,'O':14,'P':15,'Q':16,'R':17,'S':18,'T':19,'U':20,'V':21,'W':22,'X':23,'Y':24,'Z':25 } 428 | 429 | matrix =[ 430 | ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'], 431 | ['B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A'], 432 | ['C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B'], 433 | ['D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C'], 434 | ['E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D'], 435 | ['F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E'], 436 | ['G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F'], 437 | ['H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G'], 438 | ['I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], 439 | ['J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'], 440 | ['K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J'], 441 | ['L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'], 442 | ['M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L'], 443 | ['N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M'], 444 | ['O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N'], 445 | ['P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O'], 446 | ['Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P'], 447 | ['R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q'], 448 | ['S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R'], 449 | ['T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S'], 450 | ['U', 'V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T'], 451 | ['V', 'W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U'], 452 | ['W', 'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V'], 453 | ['X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W'], 454 | ['Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X'], 455 | ['Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y']] 456 | 457 | row = alpha[r] 458 | i=0 459 | while(i<26): 460 | if(matrix[row][i]==c): 461 | col=i 462 | break; 463 | i+=1 464 | 465 | return(matrix[0][col]) 466 | 467 | 468 | def vigenere(enc,key): 469 | def new_alph(ch): 470 | ch = ch.lower() 471 | alph = 'abcdefghijklmnopqrstuvwxyz' 472 | new_alph = alph[alph.index(ch):] + alph[:alph.index(ch)] 473 | return new_alph 474 | def decrypt(text, big_key): 475 | res = '' 476 | alph = 'abcdefghijklmnopqrstuvwxyz' 477 | i = 1 478 | for char in big_key: 479 | new = new_alph(char) 480 | for t in text: 481 | if alph.count(t) == 1 : 482 | res += alph[new.index(t)] 483 | text = text[i:] 484 | break 485 | elif alph.count(t.lower()) == 1: 486 | res += alph[new.index(t.lower())].upper() 487 | text = text[i:] 488 | break 489 | else: 490 | res += t 491 | text = text[i:] 492 | break 493 | i += 1 494 | return res 495 | text_dec = enc 496 | key = key 497 | if len(key) <= len(text_dec): 498 | big_key = key * (len(text_dec) // len(key)) + key[:len(text_dec) % len(key)] 499 | text_decrypt = decrypt(text_dec, big_key) 500 | return text_decrypt 501 | 502 | def xorr(key,cipher): 503 | output='' 504 | q=len(cipher) 505 | for i in range(q): 506 | c=cipher[i] 507 | a=key[i%len(key)] 508 | output+=chr(ord(c)^ord(a)) 509 | return output 510 | 511 | def vtd(cipher,key): 512 | def decrypt(message, keyword): 513 | matrix = new1(ordering(keyword), message) 514 | 515 | plaintext = ""; 516 | for r in range(len(matrix)): 517 | for c in range (len(matrix[r])): 518 | plaintext += matrix[r][c] 519 | return plaintext 520 | 521 | 522 | def new1(keySeq, message): 523 | width = len(keySeq) 524 | height = math.ceil(len(message) / width) 525 | if height * width < len(message): 526 | height += 1 527 | 528 | matrix = new2(width, height, len(message)) 529 | 530 | pos = 0 531 | for num in range(len(keySeq)): 532 | column = keySeq.index(num+1) 533 | 534 | r = 0 535 | while (r < len(matrix)) and (len(matrix[r]) > column): 536 | matrix[r][column] = message[pos] 537 | r += 1 538 | pos += 1 539 | 540 | return matrix 541 | 542 | 543 | def new2(width, height, length): 544 | matrix = [] 545 | totalAdded = 0 546 | for r in range(height): 547 | matrix.append([]) 548 | for c in range(width): 549 | if totalAdded >= length: 550 | return matrix 551 | matrix[r].append('') 552 | totalAdded += 1 553 | return matrix 554 | 555 | 556 | def ordering(keyword): 557 | sequence = [] 558 | for pos, ch in enumerate(keyword): 559 | previousLetters = keyword[:pos] 560 | newNumber = 1 561 | for previousPos, previousCh in enumerate(previousLetters): 562 | if previousCh > ch: 563 | sequence[previousPos] += 1 564 | else: 565 | newNumber += 1 566 | sequence.append(newNumber) 567 | return sequence 568 | 569 | dec = decrypt(cipher,key) 570 | return dec 571 | 572 | 573 | def crypto(): 574 | os.system('clear') 575 | banner() 576 | print('\033[1;33;40m[+]') 577 | print('\033[1;33;40m [=> Crypto Module Loaded\n') 578 | print('\033[1;33;40m [1] Base(32,64,85) Decoder ') 579 | print('\033[1;33;40m [2] Number System(Binary, Octal, Decimal, Haxadecimal) Decoder ') 580 | print('\033[1;33;40m [3] Rot(n,47) Decoder ') 581 | print('\033[1;33;40m [4] Morse Decoder ') 582 | print('\033[1;33;40m [5] RSA(Classic, Cube Root, Common Modulus, Wiener Attack, Chinese Remainder, Twin Prime) Decoder ') 583 | print('\033[1;33;40m [6] DNA Decoder ') 584 | print('\033[1;33;40m [7] BrainF#ck Decoder ') 585 | print('\033[1;33;40m [8] Bacon Decoder ') 586 | print('\033[1;33;40m [9] Vigenere Decoder ') 587 | print('\033[1;33;40m [10] XOR Decoder ') 588 | print('\033[1;33;40m [11] Vertical Transposition Decoder ') 589 | 590 | choice2=int(input('\n>')) 591 | if choice2 == 1: 592 | print('\033[1;33;40m [=> Base Decoder ') 593 | print('\033[1;33;40m [1] Base32 Decoder ') 594 | print('\033[1;33;40m [2] Base64 Decoder ') 595 | print('\033[1;33;40m [3] Base85 Decoder ') 596 | choice3=int(input('\n>')) 597 | if choice3 == 1: 598 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 599 | print("\033[1;32;40m[+][+]Found:",b32(cipher),'\n') 600 | time.sleep(2) 601 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 602 | if status==0: 603 | crypto() 604 | elif choice3==2: 605 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 606 | print("\033[1;32;40m[+][+]Found:",b64(cipher),'\n') 607 | time.sleep(2) 608 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 609 | if status==0: 610 | crypto() 611 | elif choice3==3: 612 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 613 | print("\033[1;32;40m[+][+]Found:",b85(cipher),'\n') 614 | time.sleep(2) 615 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 616 | if status==0: 617 | crypto() 618 | else: 619 | print("\033[1;31;40mWrong Option !!\n") 620 | 621 | 622 | elif choice2==2: 623 | print('\033[1;33;40m [=> Number Decoder ') 624 | print('\033[1;33;40m [1] Binary Decoder ') 625 | print('\033[1;33;40m [2] Octal Decoder ') 626 | print('\033[1;33;40m [3] Decimal Decoder ') 627 | print('\033[1;33;40m [4] Hex Decoder ') 628 | choice3=int(input('\n>')) 629 | if choice3 == 1: 630 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 631 | print("\033[1;32;40m[+][+]Found:",bintotext(cipher),'\n') 632 | time.sleep(2) 633 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 634 | if status==0: 635 | crypto() 636 | elif choice3==2: 637 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 638 | print("\033[1;32;40m[+][+]Found:",octtotext(cipher),'\n') 639 | time.sleep(2) 640 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 641 | if status==0: 642 | crypto() 643 | elif choice3==3: 644 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 645 | print("\033[1;32;40m[+][+]Found:",dectotext(cipher),'\n') 646 | time.sleep(2) 647 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 648 | if status==0: 649 | crypto() 650 | elif choice3==4: 651 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 652 | print("\033[1;32;40m[+][+]Found:",hextotext(cipher),'\n') 653 | time.sleep(2) 654 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 655 | if status==0: 656 | crypto() 657 | else: 658 | print("\033[1;31;40mWrong Option !!\n") 659 | 660 | elif choice2 == 3: 661 | print('\033[1;33;40m [=> Rot Decoder ') 662 | print('\033[1;33;40m [1] Rot(N) Decoder ') 663 | print('\033[1;33;40m [2] Rot47 Decoder ') 664 | choice3=int(input('\n>')) 665 | if choice3 == 1: 666 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 667 | for key in range(1,27): 668 | print("\033[1;32;40m[+][+]Found:",rot(cipher,key)) 669 | time.sleep(2) 670 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 671 | if status==0: 672 | crypto() 673 | elif choice3==2: 674 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 675 | print("\033[1;32;40m[+][+]Found:",rot47(cipher),'\n') 676 | time.sleep(2) 677 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 678 | if status==0: 679 | crypto() 680 | else: 681 | print("\033[1;31;40mWrong Option !!\n") 682 | 683 | elif choice2 == 4: 684 | print('\033[1;33;40m [=> Morse Decoder ') 685 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 686 | print("\033[1;32;40m[+][+]Found:",morse(cipher),'\n') 687 | time.sleep(2) 688 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 689 | if status==0: 690 | crypto() 691 | 692 | elif choice2 == 5: 693 | print('\033[1;33;40m [=> RSA Decoder ') 694 | print('\033[1;33;40m [1] Classic Attack ') 695 | print('\033[1;33;40m [2] Cube Root Attack ') 696 | print('\033[1;33;40m [3] Common Modulo Attack ') 697 | print('\033[1;33;40m [4] Weiner Attack ') 698 | print('\033[1;33;40m [5] Chinese Remainder Attack(p,q,dp,dq,c)') 699 | print('\033[1;33;40m [6] Twin Prime Attack(n1,n2,c,e)') 700 | choice3=int(input('\n>')) 701 | if choice3 == 1: 702 | cipher1=int(input('\033[1;33;40m[>] Give N: ')) 703 | cipher2=int(input('\033[1;33;40m[>] Give E: ')) 704 | cipher3=int(input('\033[1;33;40m[>] Give C: ')) 705 | print("\033[1;32;40m[+][+]Found:",classicrsa(cipher1,cipher2,cipher3),'\n') 706 | time.sleep(2) 707 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 708 | if status==0: 709 | crypto() 710 | elif choice3==2: 711 | cipher1=int(input('\033[1;33;40m[>] Give N: ')) 712 | cipher2=int(input('\033[1;33;40m[>] Give E: ')) 713 | cipher3=int(input('\033[1;33;40m[>] Give C: ')) 714 | print("\033[1;32;40m[+][+]Found:",cuberootrsa(cipher1,cipher2,cipher3),'\n') 715 | time.sleep(2) 716 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 717 | if status==0: 718 | crypto() 719 | elif choice3==3: 720 | n=int(input('\033[1;33;40m[>] Give n: ')) 721 | e1=int(input('\033[1;33;40m[>] Give e1: ')) 722 | e2=int(input('\033[1;33;40m[>] Give e2: ')) 723 | c1=int(input('\033[1;33;40m[>] Give c1: ')) 724 | c2=int(input('\033[1;33;40m[>] Give c2: ')) 725 | print("\033[1;32;40m[+][+]Found:",commonmodulo(n,e1,e2,c1,c2),'\n') 726 | time.sleep(2) 727 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 728 | if status==0: 729 | crypto() 730 | elif choice3==4: 731 | cipher1=int(input('\033[1;33;40m[>] Give N: ')) 732 | cipher2=int(input('\033[1;33;40m[>] Give E: ')) 733 | cipher3=int(input('\033[1;33;40m[>] Give C: ')) 734 | print("\033[1;32;40m[+][+]Found:",weinerrsa(cipher1,cipher2,cipher3),'\n') 735 | time.sleep(2) 736 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 737 | if status==0: 738 | crypto() 739 | elif choice3==5: 740 | cipher1=int(input('\033[1;33;40m[>] Give p: ')) 741 | cipher2=int(input('\033[1;33;40m[>] Give q: ')) 742 | cipher3=int(input('\033[1;33;40m[>] Give dp: ')) 743 | cipher4=int(input('\033[1;33;40m[>] Give dq: ')) 744 | cipher5=int(input('\033[1;33;40m[>] Give c: ')) 745 | print("\033[1;32;40m[+][+]Found:",crt(cipher1,cipher2,cipher3,cipher4,cipher5),'\n') 746 | time.sleep(2) 747 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 748 | if status==0: 749 | crypto() 750 | elif choice3==6: 751 | cipher1=int(input('\033[1;33;40m[>] Give n1: ')) 752 | cipher2=int(input('\033[1;33;40m[>] Give n2: ')) 753 | cipher3=int(input('\033[1;33;40m[>] Give c: ')) 754 | cipher4=int(input('\033[1;33;40m[>] Give e: ')) 755 | print("\033[1;32;40m[+][+]Found:",twinprime(cipher1,cipher2,cipher3,cipher4),'\n') 756 | time.sleep(2) 757 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 758 | if status==0: 759 | crypto() 760 | 761 | else: 762 | print("\033[1;31;40mWrong Option !!\n") 763 | 764 | elif choice2==6: 765 | print('\033[1;33;40m [=> DNA Decoder ') 766 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 767 | print("\033[1;32;40m[+][+]Found:",dna(cipher),'\n') 768 | time.sleep(2) 769 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 770 | if status==0: 771 | crypto() 772 | 773 | elif choice2==7: 774 | print('\033[1;33;40m [=> brainf#ck Decoder ') 775 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 776 | brainfuck(cipher) 777 | time.sleep(2) 778 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 779 | if status==0: 780 | crypto() 781 | 782 | elif choice2==8: 783 | print('\033[1;33;40m [=> Bacon Decoder ') 784 | cipher=input('\033[1;33;40m[>] Give Cipher: ') 785 | print("\033[1;32;40m[+][+]Found(26 Letter Bacon):",bacon26(cipher),'\n') 786 | print("\033[1;32;40m[+][+]Found(24 Letter Bacon):",bacon24(cipher),'\n') 787 | time.sleep(2) 788 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 789 | if status==0: 790 | crypto() 791 | 792 | elif choice2==9: 793 | print('\033[1;33;40m [=> Vignere Decoder ') 794 | cipher=input('\033[1;33;40m[>] Cipher: ') 795 | key=input('\033[1;33;40m[>] Key: ') 796 | print("\033[1;32;40m[+][+]Found:",vigenere(cipher,key),'\n') 797 | time.sleep(2) 798 | status=int(input(('\033[1;33;40mPress 0 To Get Back To Crypto Menu OR Ctrl+c '))) 799 | if status==0: 800 | crypto() 801 | 802 | elif choice2==10: 803 | print('\033[1;33;40m [=> XOR Decoder ') 804 | cipher=input('\033[1;33;40m[>] Cipher: ') 805 | key=input('\033[1;33;40m[>] Key: ') 806 | print("\033[1;32;40m[+][+]Found:",xorr(key,cipher),'\n') 807 | 808 | elif choice2==11: 809 | print('\033[1;33;40m [=> Vertical Transposition Decoder ') 810 | cipher=input('\033[1;33;40m[>] Cipher: ') 811 | key=input('\033[1;33;40m[>] Key: ') 812 | print("\033[1;32;40m[+][+]Found:",vtd(cipher,key),'\n') 813 | 814 | else: 815 | print("\033[1;31;40mWrong Option !!\n") 816 | 817 | #BANNNER 818 | def banner(): 819 | print("\033[1;31;40mDAGGER-Your Crypto Assistant") 820 | try: 821 | print("\033[1;33;40m May The Flag Be With You") 822 | time.sleep(1) 823 | crypto() 824 | except KeyboardInterrupt : 825 | sys.exit(0) 826 | --------------------------------------------------------------------------------