Skip to content

Instantly share code, notes, and snippets.

View sublime247's full-sized avatar

Kushimo Bashir sublime247

View GitHub Profile
// SPDX-License-Identifier: SEE LICENSE IN LICENSE
pragma solidity 0.8.24;
import {Test, console, console2} from "forge-std/Test.sol";
import {ChallengeTwo} from "../src/ChallengeTwo.sol";
contract MalTest is Test {
ChallengeTwo challenge;
uint8 public counter = 0;
// implementing Diffie-Hellman Encryption Algorithm
// Alice---------Bob
// Alice has a private key a=17
// Bob has a private key b = 19
// they both agree on a relative large prime number = primitive value P= 23 and G=5 avalaible publicly
// to compute alice pubic key 5^a modp
// to compute bob pubic key 5^b modp
// they both exchange thier public key to decrypt message accross the channel
// for alice to decrypt the message she takes the public key of bob B^a mod p
// implementing elgamle encryprion algorithm
// Alice------------Bob
// Bob share his public key to alice, alice then encrypt message with that key to bob, bob can then now decrypt the message
// Bob chooses a relatively large prime number P and g, which are publicly known
// Bob select a private key from a set of prime numbers {2,3 ......p-2}
// Bob computes his public key, using g^pr modP, where pr is his private key
// Alice compute an ephemeral key choosing a ny random prime number then doing g^i modP
// Alice compute the masking key by using bob pubKey with the random number he selected B^i modp
// Alice then encrypt the message Y= XKm modp, he then send Y(encrypted message) and Ephemeral Key to Bod
// Bob then compute his masking key by doing ke^pr mod P he can then now decrypt the message by doing X=Ykm^-1 mod P.