0% found this document useful (0 votes)
46 views18 pages

Crypto File 3456789

The document outlines various programming tasks related to cryptography and data security, including finding the Inverse S-Box of AES, implementing the Digital Signature Standard, converting plaintext to binary and hexadecimal formats, and using GnuPG for secure data storage and transmission. It also describes setting up a honeypot for network monitoring, studying rootkits, and demonstrating an Intrusion Detection System using Snort. Each section includes algorithms and code examples for practical implementation.

Uploaded by

vanadita sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views18 pages

Crypto File 3456789

The document outlines various programming tasks related to cryptography and data security, including finding the Inverse S-Box of AES, implementing the Digital Signature Standard, converting plaintext to binary and hexadecimal formats, and using GnuPG for secure data storage and transmission. It also describes setting up a honeypot for network monitoring, studying rootkits, and demonstrating an Intrusion Detection System using Snort. Each section includes algorithms and code examples for practical implementation.

Uploaded by

vanadita sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

PROGRAM – 3

AIM:- Write program to find Inverse S-Box of Simplified S-box of AES given
figure
ALGORITHM

• Define the S-Box:

• Create a 4x4 matrix containing the given S-Box values.

• Initialize the Inverse S-Box:

Create an empty 4x4 matrix to store the inverse S-Box values.

• Iterate through the S-Box:

For each value in the S-Box, determine its position in the inverse S-Box by:

• Calculating the row as value / 4 (integer division).


• Calculating the column as value % 4 (remainder).
• Storing the original S-Box position into the calculated location in the inverse S-Box.
• Output the Inverse S-Box:

Iterate through the inverse S-Box and display its contents.

• End Program.

CODE
#include <stdio.h>

int main() {
int s_box[4][4] = {
{0x9, 0x4, 0xA, 0xB},

{0xD, 0x1, 0x8, 0x5},


{0x6, 0x2, 0x0, 0x3},
{0xC, 0xE, 0xF, 0x7}
};
int inverse_s_box[4][4] = {0};

for (int i = 0; i < 4; i++) {


for (int j = 0; j < 4; j++) {
int value = s_box[i][j];
int row = value / 4;

int col = value % 4;


inverse_s_box[row][col] = i * 4 + j;
}
}

printf("vanadita, 11823210002\n");
printf("Inverse S-Box:\n");
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {

printf("%X ", inverse_s_box[i][j]);


}
printf("\n");
}

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

1. Input the Message: Accept the plaintext message as input.


2. Convert to Binary:
a. For each character in the message, retrieve its ASCII value.
b. Convert the ASCII value into an 8-bit binary string.
c. Append the binary string to form the binary representation of the
message.
3. Convert to Hex:
a. Group the binary string into 4-bit chunks.
b. Convert each chunk into its hexadecimal representation.
4. Output: Display the binary and hexadecimal representations.

CODE

#include <stdio.h>

#include <string.h>

void convert_to_binary(char *message, char *binary) {

int i, j;

char temp[9];

binary[0] = '\0';

for (i = 0; i < strlen(message); i++) {

int ascii = (int)message[i];


for (j = 7; j >= 0; j--) {

temp[j] = (ascii % 2) + '0';

ascii /= 2;

temp[8] = '\0';

strcat(binary, temp);

void convert_to_hex(char *binary, char *hex) {

int i, length = strlen(binary);

int value = 0;

hex[0] = '\0';

for (i = 0; i < length; i++) {

value = value * 2 + (binary[i] - '0');

if ((i + 1) % 4 == 0) {

char temp[2];

sprintf(temp, "%X", value);

strcat(hex, temp);

value = 0;

int main() {

printf("vanadita, 11823210002\n");

char message[100], binary[800], hex[200];

printf("Enter the message: ");


fgets(message, sizeof(message), stdin);

message[strcspn(message, "\n")] = '\0';

convert_to_binary(message, binary);

convert_to_hex(binary, hex);

printf("Binary representation: %s\n", binary);

printf("Hexadecimal representation: %s\n", hex);

return 0;

OUPUT :-

B. ALGORITHM

1. Read File: Open the file containing binary data.


2. Group into Bytes: Divide the binary data into groups of 8 bits (1 byte).
3. Convert to ASCII: Convert each byte to its decimal value, then to the corresponding
ASCII character.
4. Convert to Hex: Convert the binary data to hexadecimal by grouping into 4-bit
chunks.
5. Output: Display the original message and its hexadecimal representation.

CODE

#include <stdio.h>
#include <string.h>

void binary_to_ascii(char *binary, char *message) {

int i, length = strlen(binary);

char byte[9];

byte[8] = '\0';

int index = 0;

for (i = 0; i < length; i += 8) {

strncpy(byte, &binary[i], 8);

int ascii_value = strtol(byte, NULL, 2);

message[index++] = (char)ascii_value;

message[index] = '\0';

void binary_to_hex(char *binary, char *hex) {

int i, length = strlen(binary);

int value = 0;

hex[0] = '\0';

for (i = 0; i < length; i++) {

value = value * 2 + (binary[i] - '0');

if ((i + 1) % 4 == 0) {

char temp[2];

sprintf(temp, "%X", value);

strcat(hex, temp);

value = 0;

}
}

int main() {

printf("vanadita, 11823210002\n");

char binary[800], message[100], hex[200];

FILE *file = fopen("binary_input.txt", "r");

if (!file) {

printf("Error opening file!\n");

return 1;

fgets(binary, sizeof(binary), file);

fclose(file);

binary_to_ascii(binary, message);

binary_to_hex(binary, hex);

printf("Original message: %s\n", message);

printf("Hexadecimal representation: %s\n", hex);

return 0;

OUTPUT:

C. ALGORITHM

1. Read File: Open the file containing ASCII codes.


2. Convert to A-Z (mod26):
a. For each ASCII code, compute (ASCII value) % 26.
b. Add this value to 'A' to get a character in the range 'A' to 'Z'.
3. Output: Display the converted A-Z format.

CODE:

#include <stdio.h>

#include <ctype.h>

void ascii_to_mod26(char *ascii_codes, char *output) {

int i, index = 0;

for (i = 0; ascii_codes[i] != '\0'; i++) {

if (isdigit(ascii_codes[i])) {

int value = ascii_codes[i] - '0';

char letter = (value % 26) + 'A';

output[index++] = letter;

output[index] = '\0';

int main() {

printf("vanadita, 11823210002\n");

char ascii_codes[100], output[100];

FILE *file = fopen("ascii_input.txt", "r");

if (!file) {

printf("Error opening file!\n");

return 1;

}
fgets(ascii_codes, sizeof(ascii_codes), file);

fclose(file);

ascii_to_mod26(ascii_codes, output);

printf("A to Z format: %s\n", output);

return 0;

OUTPUT:
PROGRAM – 6

AIM : Demonstrate secure data storage, secure transmission, and digital


signatures using GnuPG

ALGORITHM

1. Install GnuPG: Install GnuPG if not already installed (sudo apt


install gnupg on Linux or download for Windows).
2. Generate a Key Pair:
a. Use GnuPG to create public and private keys.
3. Secure Data Storage:
a. Encrypt a file using the public key for secure storage.
b. Decrypt it with the private key.
4. Secure Transmission:
a. Encrypt a message before sending it.
b. Share the public key with the recipient for decryption.
5. Digital Signatures:
a. Sign a file using the private key.
b. Verify the signature using the public key.

CODE:
# Install GnuPG
sudo apt install gnupg

# Generate a key pair


gpg --gen-key

# List generated keys


gpg --list-keys

# Secure Data Storage: Encrypt a file


echo "This is a secret message" > message.txt
gpg -e -r "YourName" message.txt

# Decrypt the file


gpg -d message.txt.gpg

# Secure Transmission: Encrypt a message


echo "Send this securely" | gpg -e -r "RecipientName" > secure_message.gpg

# Digital Signatures: Sign a file


gpg --sign message.txt

# Verify the signature


gpg --verify message.txt.gpg
PROGRAM-7

AIM: Setup a Honeypot and Monitor it on a Network (KF Sensor)

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

1. Download KF Sensor: Obtain it from the official website.


2. Installation:
a. Install the software and configure fake ports and services.
3. Launch Honeypot:
a. Start KF Sensor and let it run on your network.
4. Analyze Logs:
a. Check logs to see intrusion attempts.
PROGRAM – 8

AIM: Installation of Rootkits and Study of Options

ALGORITHM

1. Understand Rootkits: Research about rootkits (kernel-level, user-level).


2. Simulated Environment: Create a virtual machine (e.g., VirtualBox) to
avoid compromising your primary system.
3. Install Rootkits:
a. Use a known rootkit like Knark or Adore-ng for educational purposes.
4. Analyze Rootkits:
a. Study how they hide processes/files or intercept system calls.
5. Countermeasures:
a. Use tools like chkrootkit or rkhunter to detect rootkits.
PROGRAM-9
AIM: Demonstrate Intrusion Detection System (IDS) Using Snort

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;)

Save the rule in /etc/snort/rules/local.rules.


4. Run Snort:
sudo snort -A console -q -c /etc/snort/snort.conf -i eth0

You might also like