Skip to content

Instantly share code, notes, and snippets.

@odzhan
odzhan / f8.c
Created September 15, 2024 05:56
FEAL Block Cipher Implementations from Handbook of Cryptography.
//
// FEAL-8 Block Cipher
//
#include <stdio.h>
#include <stdint.h>
// Define the Sd function as per equation (7.6)
uint8_t Sd(uint8_t x, uint8_t y, uint8_t d) {
@odzhan
odzhan / aradi.c
Last active August 12, 2024 05:17
/**
ARADI and LLAMA: Low-Latency Cryptography for Memory Encryption
Published in August 2024
Only tested on little-endian CPU.
For more details, see https://eprint.iacr.org/2024/1240
*/
#include <stdint.h>
@odzhan
odzhan / encrypt.py
Created August 3, 2024 04:45
ElGamal Encryption and Digital Signatures
# ElGamal encryption
import random
from sympy import isprime, mod_inverse
# Generate a large prime number for the modulus (p)
def generate_large_prime(bits=256):
while True:
p = random.getrandbits(bits)
if isprime(p):
@odzhan
odzhan / ecnr.py
Last active September 15, 2024 05:53
Nyberg-Rueppel Signature Scheme
import hashlib
import secrets
# Elliptic Curve Parameters (placeholders for educational purposes)
p = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F # Field prime
a = 0
b = 7
n = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 # Order of G
# Base point G (using Bitcoin's secp256k1 parameters for illustration)
@odzhan
odzhan / schnorr1.py
Last active September 15, 2024 05:50
Schnorr Digital Signatures
'''
Schnorr Digital Signature Scheme based on paper:
Efficient Signature Generation by Smart Cards, published in March 1991 by Claus-Peter Schnorr
'''
from random import randint
import sympy
import hashlib
@odzhan
odzhan / bn_ecc.c
Last active July 31, 2024 07:32
ECDH using arbitrary-precision arithmetic
/**
Running test...key : 803D8AB2E5B6E6FCA715737C3A82F7CE3C783124F6D51CD0
Session keys match...
OK.
Generating random keys...OK
Private Key for Alice : 31FA1084
Private Key for Bob : 2D748885
Generating public keys...
@odzhan
odzhan / ecdh.cpp
Last active August 6, 2024 11:22
ECC-32 Implementation
/**
ECC-32 implementation
Private Key for Alice : 775bd026
Private Key for Bob : 5133580e
Public Key for Alice : (32f20f84, 63852a02)
Public Key for Bob : (6d4444c2, 1563edf9)
Session Key for Alice : (2f3a9fa3, 6a9fa1ce)
@odzhan
odzhan / ecdh.py
Last active August 6, 2024 11:19
ECDH using P-192 prime192v1
#
# ECDH using P-192 prime192v1
#
# Runs very slow because of binary methods used.
#
import random
# Elliptic curve parameters P-192 prime192v1
p = 0xfffffffffffffffffffffffffffffffeffffffffffffffff
@odzhan
odzhan / regexp.cpp
Last active May 2, 2024 02:16
Simple regexp example using IRegExp interface.
//
// Simple regexp example using IRegExp interface.
//
/**
# Found 4 matches.
> test@gmail.com
> spam@yahoo.com
@odzhan
odzhan / mask.cpp
Last active July 3, 2024 13:28
Obfuscation with byte substitution
//
// Simple obfuscation using byte substitution
//
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <cstring>
#include <cmath>