Skip to content

Instantly share code, notes, and snippets.

#include <stdio.h>
#include <string.h>
#include <stdbool.h>
bool isPasswordOK(void) {
char Password[12];
gets(Password);
return 0 == strcmp(Password, "goodpass");
}
@uz214
uz214 / rsa-encryption.py
Created March 22, 2018 01:10 — forked from asBrettisay/rsa-encryption.py
This shows how rsa encryption is done
from fractions import gcd
import random
# Find least common multiplier
def lcm(a, b):
return (a * b) // gcd(a, b)
# Find modular inverse of a with modulo m
def modInverse(a, m):
x = 1
from Crypto.Util.number import *
p = getStrongPrime(512)
a = getRandomRange(2, p-2)
print GCD(a, p-1)
#loop until you get a GCD of 1 with p-1
base = 2
A = pow(base, a, p)
print p, base, A
import binascii, hashlib
k = "secretkey"
msg = "forge this punks"
kplus = k + "\x00"*(64-len(k))
ipad = "\x36"*64
opad = "\x5C"*64
def XOR(raw1, raw2):
@uz214
uz214 / aes-cbc.py
Created March 15, 2018 04:56 — forked from lopes/aes-cbc.py
Simple Python example of AES in CBC mode.
from hashlib import md5
from base64 import b64decode
from base64 import b64encode
from Crypto import Random
from Crypto.Cipher import AES
# Padding for the input string --not
# related to encryption itself.
BLOCK_SIZE = 16 # Bytes
@uz214
uz214 / ecb_vs_cbc.py
Created March 14, 2018 06:23 — forked from seljukgulcan/ecb_vs_cbc.py
Python CBC - ECB on Image
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img
from Crypto.Cipher import AES
from Crypto import Random
#Get the image
kyle = img.imread('kyle.png')
#Before encryption
@uz214
uz214 / ecb_vs_cbc.py
Created March 14, 2018 06:23 — forked from seljukgulcan/ecb_vs_cbc.py
Python CBC - ECB on Image
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as img
from Crypto.Cipher import AES
from Crypto import Random
#Get the image
kyle = img.imread('kyle.png')
#Before encryption
import urllib2, random
response = urllib2.urlopen("http://vip.udel.edu/crypto/mobydick.txt")
mobytext = response.read()
onlyletters = filter(lambda x: x.isalpha(), mobytext)
loweronly = onlyletters.lower()
def shiftBy(c, n):
return chr(((ord(c) - ord('a') + n) % 26) + ord('a'))