Skip to content

Instantly share code, notes, and snippets.

@odzhan
odzhan / clr_hostctrl.cpp
Created February 26, 2025 05:22
hosting
//#include "x64/Debug/mscorlib.tlh"
#import "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\mscorlib.tlb" rename("or", "or2") rename("ReportEvent", "ReportEvent2") no_namespace raw_interfaces_only
#include <iostream>
#define __IObjectHandle_INTERFACE_DEFINED__
#include <MScorEE.h>
#include <MetaHost.h>
#include <shlwapi.h>
#include <vector>
#include <fstream>
#include "objbase.h"
@odzhan
odzhan / pklnxcli.c
Created February 15, 2025 21:59
Simple Echo Servers Using Symmetric Encryption
/*
** Demo Public Key OpenSSL Echo Client
**
** Connects to an PK Echo Server. Generates RSA Key and
** sends encoded public key to server. Response is a
** session key encoded with the public key. Sends client
** request, encoded with session key, consisting of
** header and text to be echo'd between lines 'BEGIN'
** and 'END' (inclusive). Reads server response, also
** encoded with session key, consisting of header and
@odzhan
odzhan / find_exp.c
Last active October 25, 2024 20:40
Find Involutory Exponents
/**
Find involutory exponents for a modulus like a Mersenne prime: 2^31-1
Uses brute force
Very fast for small numbers, very slow for anything more than 16-bits.
gcc -O2 find_exp.c -ofind_exp -lcrypto
*/
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
@odzhan
odzhan / aperm.py
Created October 18, 2024 15:01
Affine Permutation For Obfuscation
#!/usr/bin/env python3
"""
Affine Permutation File Encoder/Decoder
This script allows you to encode and decode files using an Affine Permutation.
It uses command-line arguments to specify the operation mode (encode or decode), input file, and output file.
Additionally, it stores a SHA256 hash of the original data to verify successful decoding.
Usage:
To encode a file:
@odzhan
odzhan / prng.c
Last active October 21, 2024 19:25
LCG and ICG
/**
LCG output...
lcg(1) : 40B2947B
lcg(2) : 73718F14
lcg(3) : 6203F04B
lcg(4) : 1BB91A70
lcg(5) : 0CFC23E0
ICG output...
icg(5) : 0CFC23E0
@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 October 22, 2024 18:52
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