Crypto File 3456789
Crypto File 3456789
AIM:- Write program to find Inverse S-Box of Simplified S-box of AES given
figure
ALGORITHM
For each value in the S-Box, determine its position in the inverse S-Box by:
• End Program.
CODE
#include <stdio.h>
int main() {
int s_box[4][4] = {
{0x9, 0x4, 0xA, 0xB},
printf("vanadita, 11823210002\n");
printf("Inverse S-Box:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
return 0;
}
OUTPUT:
PROGRAM-4
AIM : Implement the Signature Scheme - Digital Signature Standard.
ALGORITHM:
1. Define Parameters:
a. Choose prime numbers ppp and qqq such that qqq divides p−1p-1p−1.
b. Select ggg, a generator of the subgroup of order qqq.
2. Generate Keys:
a. Generate a private key xxx (randomly chosen x<qx < qx<q).
b. Compute the public key y=gxmod py = g^x \mod py=gxmodp.
3. Sign the Message:
a. Choose a random integer kkk such that gcd(k,q)=1\text{gcd}(k, q) =
1gcd(k,q)=1.
b. Compute r=(gkmod p)mod qr = (g^k \mod p) \mod qr=(gkmodp)modq.
c. Compute s=(k−1×(H+x⋅r))mod qs = (k^{-1} \times (H + x \cdot r)) \mod
qs=(k−1×(H+x⋅r))modq, where HHH is the hash of the message.
4. Verify the Signature:
a. Compute w=s−1mod qw = s^{-1} \mod qw=s−1modq.
b. Calculate u1=(H⋅w)mod qu_1 = (H \cdot w) \mod qu1 =(H⋅w)modq and
u2=(r⋅w)mod qu_2 = (r \cdot w) \mod qu2 =(r⋅w)modq.
c. Compute v=((gu1⋅yu2)mod p)mod qv = ((g^{u_1} \cdot y^{u_2}) \mod p)
\mod qv=((gu1 ⋅yu2 )modp)modq.
d. Verify if v=rv = rv=r. If true, the signature is valid.
5. Output the Results:
a. Display the private key, public key, signature, and verification results.
CODE:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
long long mod_exp(long long base, long long exp, long long mod) {
long long result = 1;
base = base % mod;
while (exp > 0) {
if (exp % 2 == 1) {
result = (result * base) % mod;
}
exp = exp >> 1;
base = (base * base) % mod;
}
return result;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long mod_inverse(long long a, long long m) {
a = a % m;
for (long long x = 1; x < m; x++) {
if ((a * x) % m == 1) {
return x;
}
}
return -1;
}
int main() {
printf("vanadita, 11823210002\n");
long long p = 23;
long long q = 11;
long long g = 4;
long long x;
long long y;
srand(time(0));
x = rand() % q;
y = mod_exp(g, x, p);
printf("Private Key (x): %lld\n", x);
printf("Public Key (y): %lld\n", y);
long long H = 7;
long long k, r, s;
do {
k = rand() % q;
} while (gcd(k, q) != 1);
r = mod_exp(g, k, p) % q;
s = (mod_inverse(k, q) * (H + x * r)) % q;
printf("Signature:\n");
printf("r: %lld\n", r);
printf("s: %lld\n", s);
long long w = mod_inverse(s, q);
long long u1 = (H * w) % q;
long long u2 = (r * w) % q;
long long v = ((mod_exp(g, u1, p) * mod_exp(y, u2, p)) % p) % q;
printf("Verification:\n");
printf("v: %lld\n", v);
printf("r: %lld\n", r);
if (v == r) {
printf("Signature is valid!\n");
} else {
printf("Signature is invalid!\n");
}
return 0;
}
Output:
PROGRAM-5
AIM : ⦁ Write a Program to convert a given Message/ Plaintext into Binary
bits using ASCII Code and then covert binary bits into Hex format.
⦁ Write a program to covert given file of binary bits into Hex form and
message using ASCII codes.
⦁ C) Convert ASCII code of a file into A to Z format (mod26)
A. ALGORITHM
CODE
#include <stdio.h>
#include <string.h>
int i, j;
char temp[9];
binary[0] = '\0';
ascii /= 2;
temp[8] = '\0';
strcat(binary, temp);
int value = 0;
hex[0] = '\0';
if ((i + 1) % 4 == 0) {
char temp[2];
strcat(hex, temp);
value = 0;
int main() {
printf("vanadita, 11823210002\n");
convert_to_binary(message, binary);
convert_to_hex(binary, hex);
return 0;
OUPUT :-
B. ALGORITHM
CODE
#include <stdio.h>
#include <string.h>
char byte[9];
byte[8] = '\0';
int index = 0;
message[index++] = (char)ascii_value;
message[index] = '\0';
int value = 0;
hex[0] = '\0';
if ((i + 1) % 4 == 0) {
char temp[2];
strcat(hex, temp);
value = 0;
}
}
int main() {
printf("vanadita, 11823210002\n");
if (!file) {
return 1;
fclose(file);
binary_to_ascii(binary, message);
binary_to_hex(binary, hex);
return 0;
OUTPUT:
C. ALGORITHM
CODE:
#include <stdio.h>
#include <ctype.h>
int i, index = 0;
if (isdigit(ascii_codes[i])) {
output[index++] = letter;
output[index] = '\0';
int main() {
printf("vanadita, 11823210002\n");
if (!file) {
return 1;
}
fgets(ascii_codes, sizeof(ascii_codes), file);
fclose(file);
ascii_to_mod26(ascii_codes, output);
return 0;
OUTPUT:
PROGRAM – 6
ALGORITHM
CODE:
# Install GnuPG
sudo apt install gnupg
ALGORITHM
1. Install KF Sensor:
a. Download and install KF Sensor (Windows-based Honeypot tool).
b. Configure the honeypot to mimic vulnerable systems.
2. Configure Services:
a. Set up fake services (e.g., FTP, HTTP) to attract attackers.
3. Monitor Traffic:
a. Log network traffic and monitor attacks using KF Sensor's interface.
b. Analyze the logs for insights into attack patterns.
SETUP STEPS
ALGORITHM
ALGORITHM
1. Install Snort: Download and install Snort (sudo apt install snort on
Linux).
2. Configure Rules:
a. Create custom Snort rules for detecting suspicious activities.
3. Monitor Traffic:
a. Use Snort to monitor network traffic in real-time.
4. Generate Alerts:
a. Simulate attacks (e.g., port scans) and check if Snort detects them.
5. Analyze Logs:
a. Examine Snort logs to understand the intrusion.
SETUP STEPS
1. Install Snort:
sudo apt update
sudo apt install snort
2. Configure Snort:
a. Edit /etc/snort/snort.conf to set up network variables and
rules.
3. Create Rules:
# Example Rule: Detect ping scans
alert icmp any any -> any any (msg:"ICMP Ping detected";
sid:1000001;)