SlideShare a Scribd company logo
1 of 3
Download to read offline
Develop an encryption and decryption algorithm Your program should accept an input file to be
compressed and encrypted and the saved files should be both the compressed and encrypted files.
Your program should also be able to recover the encrypted and decrypted files create the
Huffman codes to compress a set of files and recover the files. Alert the user the compression
ratio. This will be simulated if the file is stored as a *.txt file The compressed file must be
encrypted prior to saving the file. Add the following methods to your compression: Huffman
LZW Write an explanation as to how the methods work in your code -Add the follow methods
to both your encryption and decryption methods: Simple Encryption Public-Key Cryptosystem
RSA Cryptosystem Implement the ability to save the files as Binary I/O (0 and 1)
Solution
import javax.swing.*;
import java.security.SecureRandom;
import javax.crypto.Cipher;
import javax.crypto.KeyGenerator;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.util.Random ;
class AES {
byte[] skey = new byte[1000];
String skeyString;
static byte[] raw;
String inputMessage,encryptedData,decryptedMessage;
public AES() {
try {
generateSymmetricKey();
inputMessage=JOptionPane.showInputDialog(null,"Enter message to encrypt");
byte[] ibyte = inputMessage.getBytes();
byte[] ebyte=encrypt(raw, ibyte);
String encryptedData = new String(ebyte);
System.out.println("Encrypted message "+encryptedData);
JOptionPane.showMessageDialog(null,"Encrypted Data "+" "+encryptedData);
byte[] dbyte= decrypt(raw,ebyte);
String decryptedMessage = new String(dbyte);
System.out.println("Decrypted message "+decryptedMessage);
JOptionPane.showMessageDialog(null,"Decrypted Data "+" "+decryptedMessage);
}
catch(Exception e) {
System.out.println(e);
}
}
void generateSymmetricKey() {
try {
Random r = new Random();
int num = r.nextInt(10000);
String knum = String.valueOf(num);
byte[] knumb = knum.getBytes();
skey=getRawKey(knumb);
skeyString = new String(skey);
System.out.println("AES Symmetric key = "+skeyString);
}
catch(Exception e) {
System.out.println(e);
}
}
private static byte[] getRawKey(byte[] seed) throws Exception {
KeyGenerator kgen = KeyGenerator.getInstance("AES");
SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");
sr.setSeed(seed);
kgen.init(128, sr); // 192 and 256 bits may not be available
SecretKey skey = kgen.generateKey();
raw = skey.getEncoded();
return raw;
}
private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
byte[] encrypted = cipher.doFinal(clear);
return encrypted;
}
private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception {
SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
Cipher cipher = Cipher.getInstance("AES");
cipher.init(Cipher.DECRYPT_MODE, skeySpec);
byte[] decrypted = cipher.doFinal(encrypted);
return decrypted;
}
public static void main(String args[]) {
AES aes = new AES();
}
}

More Related Content

Similar to Develop an encryption and decryption algorithm Your program should a.pdf

Distributed systems
Distributed systemsDistributed systems
Distributed systemsSonali Parab
 
Network security
Network securityNetwork security
Network securitybabyangle
 
Please I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdfPlease I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdfasenterprisestyagi
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsAleksandr Yampolskiy
 
Tutorial s crypto api session keys
Tutorial   s crypto api session keysTutorial   s crypto api session keys
Tutorial s crypto api session keysDr. Edwin Hernandez
 
Multi client
Multi clientMulti client
Multi clientganteng8
 
Task 4 The key is hardcoded in the provided source DES enc.pdf
Task 4  The key is hardcoded in the provided source DES enc.pdfTask 4  The key is hardcoded in the provided source DES enc.pdf
Task 4 The key is hardcoded in the provided source DES enc.pdfabcfootcare
 
Learning Java 4 – Swing, SQL, and Security API
Learning Java 4 – Swing, SQL, and Security APILearning Java 4 – Swing, SQL, and Security API
Learning Java 4 – Swing, SQL, and Security APIcaswenson
 
Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019Balázs Tatár
 
Secure preferences
Secure preferencesSecure preferences
Secure preferencesJain Zang
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambaryoyomay93
 
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdfGetting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdfNicholasflqStewartl
 
Protect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada KeystoreProtect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada KeystoreStephane Carrez
 

Similar to Develop an encryption and decryption algorithm Your program should a.pdf (20)

Distributed systems
Distributed systemsDistributed systems
Distributed systems
 
Ac2
Ac2Ac2
Ac2
 
Network security
Network securityNetwork security
Network security
 
Please I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdfPlease I am trying to get this code to output in -txt file- I need you.pdf
Please I am trying to get this code to output in -txt file- I need you.pdf
 
Eight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programsEight simple rules to writing secure PHP programs
Eight simple rules to writing secure PHP programs
 
Network security
Network securityNetwork security
Network security
 
Tutorial s crypto api session keys
Tutorial   s crypto api session keysTutorial   s crypto api session keys
Tutorial s crypto api session keys
 
Multi client
Multi clientMulti client
Multi client
 
Java practical
Java practicalJava practical
Java practical
 
Task 4 The key is hardcoded in the provided source DES enc.pdf
Task 4  The key is hardcoded in the provided source DES enc.pdfTask 4  The key is hardcoded in the provided source DES enc.pdf
Task 4 The key is hardcoded in the provided source DES enc.pdf
 
Lecture6
Lecture6Lecture6
Lecture6
 
Id32
Id32Id32
Id32
 
Backdoor coding
Backdoor codingBackdoor coding
Backdoor coding
 
Learning Java 4 – Swing, SQL, and Security API
Learning Java 4 – Swing, SQL, and Security APILearning Java 4 – Swing, SQL, and Security API
Learning Java 4 – Swing, SQL, and Security API
 
Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019Let's write secure Drupal code! - DrupalCamp London 2019
Let's write secure Drupal code! - DrupalCamp London 2019
 
Secure preferences
Secure preferencesSecure preferences
Secure preferences
 
MultiClient chatting berbasis gambar
MultiClient chatting berbasis gambarMultiClient chatting berbasis gambar
MultiClient chatting berbasis gambar
 
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdfGetting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
Getting error - (Return type of out-of-line definition of 'Product--Ge (1).pdf
 
Protect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada KeystoreProtect Sensitive Data with Ada Keystore
Protect Sensitive Data with Ada Keystore
 
ExtraFileIO.pptx
ExtraFileIO.pptxExtraFileIO.pptx
ExtraFileIO.pptx
 

More from deepaksatrker

Cystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdf
Cystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdfCystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdf
Cystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdfdeepaksatrker
 
Compute the addition and multiplication of the following 2 binary fl.pdf
Compute the addition and multiplication of the following 2 binary fl.pdfCompute the addition and multiplication of the following 2 binary fl.pdf
Compute the addition and multiplication of the following 2 binary fl.pdfdeepaksatrker
 
BIOCHEMList and briefly describe the six types of the 6 basic rec.pdf
BIOCHEMList and briefly describe the six types of the 6 basic rec.pdfBIOCHEMList and briefly describe the six types of the 6 basic rec.pdf
BIOCHEMList and briefly describe the six types of the 6 basic rec.pdfdeepaksatrker
 
Write an audit memo that explains how quality control for an audit e.pdf
Write an audit memo that explains how quality control for an audit e.pdfWrite an audit memo that explains how quality control for an audit e.pdf
Write an audit memo that explains how quality control for an audit e.pdfdeepaksatrker
 
What legal impacts did the ACA have on tax-exempt hospitalsSolu.pdf
What legal impacts did the ACA have on tax-exempt hospitalsSolu.pdfWhat legal impacts did the ACA have on tax-exempt hospitalsSolu.pdf
What legal impacts did the ACA have on tax-exempt hospitalsSolu.pdfdeepaksatrker
 
Which members of the family above are afflicted with Huntingtons Di.pdf
Which members of the family above are afflicted with Huntingtons Di.pdfWhich members of the family above are afflicted with Huntingtons Di.pdf
Which members of the family above are afflicted with Huntingtons Di.pdfdeepaksatrker
 
What could be the arguments of a production functionA Cost and La.pdf
What could be the arguments of a production functionA Cost and La.pdfWhat could be the arguments of a production functionA Cost and La.pdf
What could be the arguments of a production functionA Cost and La.pdfdeepaksatrker
 
What are the benefits to firms of international diversification Wha.pdf
What are the benefits to firms of international diversification Wha.pdfWhat are the benefits to firms of international diversification Wha.pdf
What are the benefits to firms of international diversification Wha.pdfdeepaksatrker
 
What are electromagnetic wavesSolutionWe are encompassed by w.pdf
What are electromagnetic wavesSolutionWe are encompassed by w.pdfWhat are electromagnetic wavesSolutionWe are encompassed by w.pdf
What are electromagnetic wavesSolutionWe are encompassed by w.pdfdeepaksatrker
 
Using RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdfUsing RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdfdeepaksatrker
 
tnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdf
tnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdftnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdf
tnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdfdeepaksatrker
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfdeepaksatrker
 
The structure of a high temperature superconductor containing barium.pdf
The structure of a high temperature superconductor containing barium.pdfThe structure of a high temperature superconductor containing barium.pdf
The structure of a high temperature superconductor containing barium.pdfdeepaksatrker
 
The present value o.pdf
The present value o.pdfThe present value o.pdf
The present value o.pdfdeepaksatrker
 
The Associated Handles section in Resource Monitor can be used to sh.pdf
The Associated Handles section in Resource Monitor can be used to sh.pdfThe Associated Handles section in Resource Monitor can be used to sh.pdf
The Associated Handles section in Resource Monitor can be used to sh.pdfdeepaksatrker
 
T 5. A contract should be held enforceable even if a party is mistake.pdf
T 5. A contract should be held enforceable even if a party is mistake.pdfT 5. A contract should be held enforceable even if a party is mistake.pdf
T 5. A contract should be held enforceable even if a party is mistake.pdfdeepaksatrker
 
Subject - Project ManagementDescribe what the WBS is and why you .pdf
Subject - Project ManagementDescribe what the WBS is and why you .pdfSubject - Project ManagementDescribe what the WBS is and why you .pdf
Subject - Project ManagementDescribe what the WBS is and why you .pdfdeepaksatrker
 
Significant mass extinctions occurred during which of the following .pdf
Significant mass extinctions occurred during which of the following .pdfSignificant mass extinctions occurred during which of the following .pdf
Significant mass extinctions occurred during which of the following .pdfdeepaksatrker
 
SOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdf
SOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdfSOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdf
SOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdfdeepaksatrker
 
Please help with the English test !!! Thank you very much!Identify.pdf
Please help with the English test !!! Thank you very much!Identify.pdfPlease help with the English test !!! Thank you very much!Identify.pdf
Please help with the English test !!! Thank you very much!Identify.pdfdeepaksatrker
 

More from deepaksatrker (20)

Cystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdf
Cystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdfCystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdf
Cystic fibrosis is caused by a recessive mutant allele (cf). Two norm.pdf
 
Compute the addition and multiplication of the following 2 binary fl.pdf
Compute the addition and multiplication of the following 2 binary fl.pdfCompute the addition and multiplication of the following 2 binary fl.pdf
Compute the addition and multiplication of the following 2 binary fl.pdf
 
BIOCHEMList and briefly describe the six types of the 6 basic rec.pdf
BIOCHEMList and briefly describe the six types of the 6 basic rec.pdfBIOCHEMList and briefly describe the six types of the 6 basic rec.pdf
BIOCHEMList and briefly describe the six types of the 6 basic rec.pdf
 
Write an audit memo that explains how quality control for an audit e.pdf
Write an audit memo that explains how quality control for an audit e.pdfWrite an audit memo that explains how quality control for an audit e.pdf
Write an audit memo that explains how quality control for an audit e.pdf
 
What legal impacts did the ACA have on tax-exempt hospitalsSolu.pdf
What legal impacts did the ACA have on tax-exempt hospitalsSolu.pdfWhat legal impacts did the ACA have on tax-exempt hospitalsSolu.pdf
What legal impacts did the ACA have on tax-exempt hospitalsSolu.pdf
 
Which members of the family above are afflicted with Huntingtons Di.pdf
Which members of the family above are afflicted with Huntingtons Di.pdfWhich members of the family above are afflicted with Huntingtons Di.pdf
Which members of the family above are afflicted with Huntingtons Di.pdf
 
What could be the arguments of a production functionA Cost and La.pdf
What could be the arguments of a production functionA Cost and La.pdfWhat could be the arguments of a production functionA Cost and La.pdf
What could be the arguments of a production functionA Cost and La.pdf
 
What are the benefits to firms of international diversification Wha.pdf
What are the benefits to firms of international diversification Wha.pdfWhat are the benefits to firms of international diversification Wha.pdf
What are the benefits to firms of international diversification Wha.pdf
 
What are electromagnetic wavesSolutionWe are encompassed by w.pdf
What are electromagnetic wavesSolutionWe are encompassed by w.pdfWhat are electromagnetic wavesSolutionWe are encompassed by w.pdf
What are electromagnetic wavesSolutionWe are encompassed by w.pdf
 
Using RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdfUsing RustBecause postfix expressions are simpler and faster to ev.pdf
Using RustBecause postfix expressions are simpler and faster to ev.pdf
 
tnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdf
tnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdftnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdf
tnt en Assignment Nickele Company reoorts net income of sae,4n0 in .pdf
 
This file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdfThis file contains a complete array-based MultiSet, but not the code.pdf
This file contains a complete array-based MultiSet, but not the code.pdf
 
The structure of a high temperature superconductor containing barium.pdf
The structure of a high temperature superconductor containing barium.pdfThe structure of a high temperature superconductor containing barium.pdf
The structure of a high temperature superconductor containing barium.pdf
 
The present value o.pdf
The present value o.pdfThe present value o.pdf
The present value o.pdf
 
The Associated Handles section in Resource Monitor can be used to sh.pdf
The Associated Handles section in Resource Monitor can be used to sh.pdfThe Associated Handles section in Resource Monitor can be used to sh.pdf
The Associated Handles section in Resource Monitor can be used to sh.pdf
 
T 5. A contract should be held enforceable even if a party is mistake.pdf
T 5. A contract should be held enforceable even if a party is mistake.pdfT 5. A contract should be held enforceable even if a party is mistake.pdf
T 5. A contract should be held enforceable even if a party is mistake.pdf
 
Subject - Project ManagementDescribe what the WBS is and why you .pdf
Subject - Project ManagementDescribe what the WBS is and why you .pdfSubject - Project ManagementDescribe what the WBS is and why you .pdf
Subject - Project ManagementDescribe what the WBS is and why you .pdf
 
Significant mass extinctions occurred during which of the following .pdf
Significant mass extinctions occurred during which of the following .pdfSignificant mass extinctions occurred during which of the following .pdf
Significant mass extinctions occurred during which of the following .pdf
 
SOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdf
SOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdfSOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdf
SOLUTIONNotice thatt2becomes simpler when differentiated (wherease5t.pdf
 
Please help with the English test !!! Thank you very much!Identify.pdf
Please help with the English test !!! Thank you very much!Identify.pdfPlease help with the English test !!! Thank you very much!Identify.pdf
Please help with the English test !!! Thank you very much!Identify.pdf
 

Recently uploaded

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...Nguyen Thanh Tu Collection
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfPondicherry University
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111GangaMaiya1
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxCeline George
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptNishitharanjan Rout
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsNbelano25
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 

Recently uploaded (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 

Develop an encryption and decryption algorithm Your program should a.pdf

  • 1. Develop an encryption and decryption algorithm Your program should accept an input file to be compressed and encrypted and the saved files should be both the compressed and encrypted files. Your program should also be able to recover the encrypted and decrypted files create the Huffman codes to compress a set of files and recover the files. Alert the user the compression ratio. This will be simulated if the file is stored as a *.txt file The compressed file must be encrypted prior to saving the file. Add the following methods to your compression: Huffman LZW Write an explanation as to how the methods work in your code -Add the follow methods to both your encryption and decryption methods: Simple Encryption Public-Key Cryptosystem RSA Cryptosystem Implement the ability to save the files as Binary I/O (0 and 1) Solution import javax.swing.*; import java.security.SecureRandom; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; import javax.crypto.spec.SecretKeySpec; import java.util.Random ; class AES { byte[] skey = new byte[1000]; String skeyString; static byte[] raw; String inputMessage,encryptedData,decryptedMessage; public AES() { try { generateSymmetricKey(); inputMessage=JOptionPane.showInputDialog(null,"Enter message to encrypt"); byte[] ibyte = inputMessage.getBytes(); byte[] ebyte=encrypt(raw, ibyte); String encryptedData = new String(ebyte); System.out.println("Encrypted message "+encryptedData); JOptionPane.showMessageDialog(null,"Encrypted Data "+" "+encryptedData); byte[] dbyte= decrypt(raw,ebyte); String decryptedMessage = new String(dbyte); System.out.println("Decrypted message "+decryptedMessage);
  • 2. JOptionPane.showMessageDialog(null,"Decrypted Data "+" "+decryptedMessage); } catch(Exception e) { System.out.println(e); } } void generateSymmetricKey() { try { Random r = new Random(); int num = r.nextInt(10000); String knum = String.valueOf(num); byte[] knumb = knum.getBytes(); skey=getRawKey(knumb); skeyString = new String(skey); System.out.println("AES Symmetric key = "+skeyString); } catch(Exception e) { System.out.println(e); } } private static byte[] getRawKey(byte[] seed) throws Exception { KeyGenerator kgen = KeyGenerator.getInstance("AES"); SecureRandom sr = SecureRandom.getInstance("SHA1PRNG"); sr.setSeed(seed); kgen.init(128, sr); // 192 and 256 bits may not be available SecretKey skey = kgen.generateKey(); raw = skey.getEncoded(); return raw; } private static byte[] encrypt(byte[] raw, byte[] clear) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, skeySpec); byte[] encrypted = cipher.doFinal(clear); return encrypted; }
  • 3. private static byte[] decrypt(byte[] raw, byte[] encrypted) throws Exception { SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES"); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.DECRYPT_MODE, skeySpec); byte[] decrypted = cipher.doFinal(encrypted); return decrypted; } public static void main(String args[]) { AES aes = new AES(); } }