0% found this document useful (0 votes)
804 views3 pages

Practical - 3: Aim:-Implement Monoalphabetic Cipher Encryption-Decryption. Introduction

This document describes an implementation of a monoalphabetic cipher for encryption and decryption. The cipher uses two character arrays to map each plain text character to an encrypted character and vice versa. The program takes a plain text message as input, encrypts it using the cipher mapping, displays the encrypted text, decrypts the encrypted text back to the original plain text, and displays the decrypted text. The program successfully encrypts and decrypts messages using a monoalphabetic cipher.

Uploaded by

Pranav Patel
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)
804 views3 pages

Practical - 3: Aim:-Implement Monoalphabetic Cipher Encryption-Decryption. Introduction

This document describes an implementation of a monoalphabetic cipher for encryption and decryption. The cipher uses two character arrays to map each plain text character to an encrypted character and vice versa. The program takes a plain text message as input, encrypts it using the cipher mapping, displays the encrypted text, decrypts the encrypted text back to the original plain text, and displays the decrypted text. The program successfully encrypts and decrypts messages using a monoalphabetic cipher.

Uploaded by

Pranav Patel
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

En. No.

:- 190163116023 6th IT (B4)

Practical – 3

Aim :- Implement Monoalphabetic cipher encryption-decryption.


Introduction:-
 Monoalphabetic cipher is a substitution cipher in which for a given key, the
cipher alphabet for each plain alphabet is fixed throughout the encryption
process.
 For example, if ‘A’ is encrypted as ‘D’, for any number of occurrence in that
plaintext, ‘A’ will always get encrypted to ‘D’.

MonoalphabeticCipher.java:-
import java.util.Scanner;
public class MonoalphabeticCipher
{
public static char p[] = {
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v',
'w', 'x', 'y', 'z'
};
public static char ch[] = {
'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O',
'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J',
'K', 'L', 'Z', 'X', 'C',
'V', 'B', 'N', 'M'
};

public static String doEncryption(String s)


{
char c[] = new char[(s.length())];
for (int i = 0; i < s.length(); i++)
{
for (int j = 0; j < 26; j++)
{
if (p[j] == s.charAt(i))
{
c[i] = ch[j];
break;
}
}

CNS(3161606) 1
En. No.:- 190163116023 6th IT (B4)

}
return (new String(c));
}

public static String doDecryption(String s)


{
char p1[] = new char[(s.length())];
for (int i = 0; i < s.length(); i++)
{
for (int j = 0; j < 26; j++)
{
if (ch[j] == s.charAt(i))
{
p1[i] = p[j];
break;
}
}
}
return (new String(p1));
}

public static void main(String args[])


{
Scanner sc = new Scanner(System.in);
System.out.println("Enter the message: ");
String en = doEncryption(sc.next().toLowerCase());
System.out.println("Encrypted message: " + en);
System.out.println("Decrypted message: " + doDecryption(en));
sc.close();
}
}

CNS(3161606) 2
En. No.:- 190163116023 6th IT (B4)

Output:-

CNS(3161606) 3

You might also like