Easily the best teacher I've come across for teaching programming! I'm not quite a beginner but my knowledge was pretty disorganized and scattered, your videos help me a great deal! thank you! keep up the awesome work Bro!!!!
IMPORTANT NOTE: This is a substitution cipher and not OTP. My bad //*********************************************************** public class Main { public static void main(String[] args) {
EncryptionProgram ep = new EncryptionProgram(); } } //*********************************************************** import java.util.*; public class EncryptionProgram { private Scanner scanner; private Random random; private ArrayList list; private ArrayList shuffledList; private char character; private String line; private char[] letters;
EncryptionProgram(){ scanner = new Scanner(System.in); random = new Random(); list = new ArrayList(); shuffledList = new ArrayList(); character = ' '; newKey(); askQuestion(); } private void askQuestion(){ while(true) { System.out.println("********************************************"); System.out.println("What do you want to do?"); System.out.println("(N)ewKey,(G)etKey,(E)ncrypt,(D)ecrypt,(Q)uit"); char response = Character.toUpperCase(scanner.nextLine().charAt(0));
switch(response) { case 'N': newKey(); break; case 'G': getKey(); break; case 'E': encrypt(); break; case 'D': decrypt(); break; case 'Q': quit(); break; default: System.out.println("Not a valid answer :("); } } } private void newKey(){
character = ' '; list.clear(); shuffledList.clear();
Ideea: add two new methods: saveKey() and setKey(). Save the key to a file and then reload that key from the file. So, two way encrypted communication based on a common key file. Ofcourse that key file can be encrypted with a known variable (like a password). Just shifted a few chars. That way even if someone has the keyfile, still needs to unshift the key in order to work.
I second that. I have a project that involves a login screen, a create account screen, and a user's screen. Each user has their own .ser file, so that when they log in, the login page looks for their username.ser file and checks out if it(and their password) matches. I got stumped on the administration page, though. As administrator, I want to be able to see all of the users. For some reason, the program only remembers the last user created and overwrites any that were created before. I can't seem to make the arraylist permanent.
I am a year late, but I am assuming that he assumed that that we will not notice and not assume that it's pointless, but I also assume that he assumed that we will use it in the video.
I find it inconvenient as the all the data is clear when I terminate the program . I want to restore the previous data when I start over the program . I recall that you have taught me how save object's information and reload it by using serialization and deserialization . I think it's a good practice and challenge for me to combine the encryption , serialization and deserialization together . Here's my code . Class : UserInfo import java.io.Serializable; import java.util.ArrayList;
// encrypt the message . private void encrypt() { System.out.println("Please send a a message for encryption :") ; String message = scanner.nextLine() ; userMessage = message ; encryptedUserMessage = "" ; // it will = null if no initialization . letterArray = message.toCharArray() ;
int i = 0 ; for (char x : letterArray) { letterArray[i++] = shuffledList.get(list.indexOf(x)) ; encryptedUserMessage += shuffledList.get(list.indexOf(x)) ; }
System.out.println(letterArray) ; }
// decrypt the message . private void decrypt() { System.out.println("Please send a a message for decryption :") ; String message = scanner.nextLine() ; letterArray = message.toCharArray() ;
int i = 0 ; for (char x : letterArray) { letterArray[i++] = list.get(shuffledList.indexOf(x)) ; }
// create a file to store you object'sinformation . FileInputStream fileIn = new FileInputStream("C:\\Users\\wwwha\\eclipse-workspace\\Serializer\\src\\userInfo.ser") ; ObjectInputStream objectIn = new ObjectInputStream(fileIn) ; // User class is not recorded in file so we need to cast it as the object type . userInfo = (UserInfo) objectIn.readObject() ;
// create a file to store you object'sinformation . FileOutputStream fileOut = new FileOutputStream("src/userInfo.ser") ; ObjectOutputStream objectOut = new ObjectOutputStream(fileOut) ; objectOut.writeObject(userInfo) ;
fileOut.close() ; objectOut.close() ;
System.out.println("UserInfo saved .") ; System.out.println("See you next time .") ; System.exit(9) ; } } Class : Main import java.io.IOException;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, IOException {
EncryptionProgram ep = new EncryptionProgram() ; } }
Nice tutorial but this is not One-time pad encryption. This is a simple replacement encryption and can be cracked with the proper program and a sufficient large message.
for encrypt method I think it will be better if we wrote it like this: private void encrypt(){ System.out.print(" Enter a message to be encrypted :"); line = scanner.next(); int lineLength = line.length(); this.letters = new char[lineLength]; for(int i = 0; i < lineLength; i++) letters[i] = shuffledList.get( list.indexOf( line.charAt(i) ) ); System.out.println("Your encrypted message is :" + String.copyValueOf(letters)); }
You actually dont need the list.indexOf part. You could just write: letters[i] = shuffledList.get(line.charAt(i) - 32); Since the ASCII character value at index of i in line is 32 ahead of where it positionally is in list/shuffledList. This way, you don't need to hunt thru list to find the index of that character.
You don't get to print the whole ASCII table. He only prints the printable characters from that table. (32-126). The rest are special characters used by the Operating System.
I find another quicker way to encrypt the message instead of nested loop . I use the listName.indexOf(element) . // You can use it with an non-primitive array by changing it to list first . // Arrays.asList(arrayName).indexOf(element) private void encrypt() { System.out.println("Please send a a message for encryption :") ; String message = scanner.nextLine() ; letterArray = message.toCharArray() ;
int i = 0 ; for (char x : letterArray) { letterArray[i++] = shuffledList.get(list.indexOf(x)) ; } System.out.println(letterArray) ; // array cannot be print directly as only string representation will be shown , except char array . }
My friend, I want to know the basics in order, lesson by lesson, to reach a professional level in java, put it in a post or video, because I completed the data structures, but I am not at the level
I cannot see the code listed in the description as mentioned in the video. I really liked this and did it (well I thought I did) but it will not launch at all. eclipse just says "The Selection cannot be launched, and there are no recent launches." I have not freakin idea what this means or how to fix it. But Thanks anyway. Actually I just fixed it. If anyone else is having this issue and a newbie like me.... select the main java tab (not the Encryption program ) tab and run the java script from there
Wow - I actually got this to work in the end - took me an extra hour to debug my errors and it works well. now I just need to figure our how to convert this same theory into 1 - a GUI and 2 - instead of using ASCII as the code base I want to use the Blockchain BIP39 reference chart
Your classpath may be broken, try (in Eclipse): Run -> Run configurations -> select the class that contains the main() method for your project -> Run This error occurs when the JVM can't find your class when it compiles
public class Main { public static void main(String[] args) {
EncryptionProgram ep = new EncryptionProgram();
} } ************************************************************************************************ import java.util.*; public class EncryptionProgram {
EncryptionProgram(){ scanner = new Scanner(System.in); random = new Random(); list = new ArrayList(); shuffledList = new ArrayList(); character = ' ';
newKey(); askQuestion();
} private void askQuestion(){ while(true){ System.out.println("********************************************"); System.out.println("What do you want to do?"); System.out.println("(N)ewKey,(G)etKey,(E)ncrypt,(D)ecrypt,(Q)uit"); char response = Character.toUpperCase(scanner.nextLine().charAt(0));
switch(response){ case 'N': newKey(); break; case 'G': getKey(); break; case 'E': encrypt(); break; case 'D': decrypt(); break; case 'Q': quit(); break; default: System.out.println("Not a valid answer :("); }
} } private void newKey(){
character = ' '; list.clear(); shuffledList.clear();
Hey hope you are doing alright just I wanna say that GOD loved the world so much he sent his only begotten son Jesus to die a brutal death for us so that we can have eternal life and we can all accept this amazing gift this by simply trusting in Jesus, confessing that GOD raised him from the dead, turning away from your sins and forming a relationship with GOD.
Easily the best teacher I've come across for teaching programming! I'm not quite a beginner but my knowledge was pretty disorganized and scattered, your videos help me a great deal! thank you! keep up the awesome work Bro!!!!
just found this channel by accident, subscribed without a hesitation. keep up with the UNIQUE and WHOLESOME work man!
IMPORTANT NOTE: This is a substitution cipher and not OTP. My bad
//***********************************************************
public class Main {
public static void main(String[] args) {
EncryptionProgram ep = new EncryptionProgram();
}
}
//***********************************************************
import java.util.*;
public class EncryptionProgram {
private Scanner scanner;
private Random random;
private ArrayList list;
private ArrayList shuffledList;
private char character;
private String line;
private char[] letters;
EncryptionProgram(){
scanner = new Scanner(System.in);
random = new Random();
list = new ArrayList();
shuffledList = new ArrayList();
character = ' ';
newKey();
askQuestion();
}
private void askQuestion(){
while(true) {
System.out.println("********************************************");
System.out.println("What do you want to do?");
System.out.println("(N)ewKey,(G)etKey,(E)ncrypt,(D)ecrypt,(Q)uit");
char response = Character.toUpperCase(scanner.nextLine().charAt(0));
switch(response) {
case 'N':
newKey();
break;
case 'G':
getKey();
break;
case 'E':
encrypt();
break;
case 'D':
decrypt();
break;
case 'Q':
quit();
break;
default:
System.out.println("Not a valid answer :(");
}
}
}
private void newKey(){
character = ' ';
list.clear();
shuffledList.clear();
for(int i=32;i
I think you should pin the message bro
No randaom use in whole code .😢
Strains of, Car car equals new car, and, Dog dog equals new dog, keep rolling through my head. good job. thank you
Ideea: add two new methods:
saveKey() and setKey().
Save the key to a file and then reload that key from the file.
So, two way encrypted communication based on a common key file.
Ofcourse that key file can be encrypted with a known variable (like a password). Just shifted a few chars. That way even if someone has the keyfile, still needs to unshift the key in order to work.
You have such a hacker brain :)
I second that. I have a project that involves a login screen, a create account screen, and a user's screen. Each user has their own .ser file, so that when they log in, the login page looks for their username.ser file and checks out if it(and their password) matches. I got stumped on the administration page, though. As administrator, I want to be able to see all of the users. For some reason, the program only remembers the last user created and overwrites any that were created before. I can't seem to make the arraylist permanent.
i have the same idea of taht set key and i tried to implemnt that but somehow my array isnt geeting coverted into array list
Awesome. Thank you Bro! This project is very useful. The way you teach is just AWESOME!
man! this was so cool and easy to learn! Thanks for this :) 💜
7:27 🤔Why we declared "random" and initialized but didn't use it ?
I am a year late, but I am assuming that he assumed that that we will not notice and not assume that it's pointless, but I also assume that he assumed that we will use it in the video.
Program complete. This walkthrough is golden. Thanks, Bro!
thanks man, gonna use this skill for my upcoming internship!
I find it inconvenient as the all the data is clear when I terminate the program .
I want to restore the previous data when I start over the program .
I recall that you have taught me how save object's information and reload it by using serialization and deserialization .
I think it's a good practice and challenge for me to combine the encryption , serialization and deserialization together .
Here's my code .
Class : UserInfo
import java.io.Serializable;
import java.util.ArrayList;
public class UserInfo implements Serializable {
private static final long serialVersionUID = 1L;
ArrayList list ;
ArrayList shuffledList ;
String userMessage , encryptedUserMessage ;
}
Class : EncryptionProgram
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import java.io.* ;
public class EncryptionProgram {
transient private Scanner scanner ;
private ArrayList list ;
private ArrayList shuffledList ; // shuffled(洗牌的)
private char character ;
private char[] letterArray ;
private String userMessage , encryptedUserMessage ;
EncryptionProgram() throws ClassNotFoundException, IOException {
scanner = new Scanner(System.in);
list = new ArrayList() ;
shuffledList = new ArrayList() ;
character = ' ' ; // ASCII values of [space] = 32
askQuestion() ;
}
private void askQuestion() throws ClassNotFoundException, IOException {
while (true) {
System.out.println("**************************") ;
System.out.println("What do you want to do ?") ;
System.out.println("[(L)oad , (N)ewKey] , (G)etKey , (E)ncrypt , (D)ecrypt , (M)essage , (Q)uit") ;
char responseChar = Character.toUpperCase(scanner.nextLine().charAt(0)) ;
switch (responseChar) {
case 'L' :
load() ;
break ;
case 'N' :
newKey() ;
break ;
case 'G' :
getKey() ;
break ;
case 'E' :
encrypt() ;
break ;
case 'D' :
decrypt() ;
break ;
case 'M' :
message() ;
break ;
case 'Q' :
quit() ;
break ;
default :
System.out.println("Not a valid answer .") ;
break ;
}
}
}
// generate new key .
private void newKey() {
// reset the character to 32 .
character = ' ' ; // ASCII values of [space] = 32
list.clear() ;
shuffledList.clear() ;
encryptedUserMessage = "" ;
// ASCII decimal (32-126) , 32 = [space] , 127 = [DEL] ;
for (int i = 32 ; i < 127 ; i++ ) {
list.add(Character.valueOf(character++)) ;
}
shuffledList = new ArrayList(list) ;
Collections.shuffle(shuffledList) ;
System.out.println("A new key has been generated .") ;
}
// retrieve the key .
private void getKey() {
System.out.println("Key : ") ;
for(Character x : list) {
System.out.print(x) ;
}
System.out.println() ;
System.out.println("Shuffled key : ") ;
for(Character x : shuffledList) {
System.out.print(x) ;
}
System.out.println() ;
}
// encrypt the message .
private void encrypt() {
System.out.println("Please send a a message for encryption :") ;
String message = scanner.nextLine() ;
userMessage = message ;
encryptedUserMessage = "" ; // it will = null if no initialization .
letterArray = message.toCharArray() ;
int i = 0 ;
for (char x : letterArray) {
letterArray[i++] = shuffledList.get(list.indexOf(x)) ;
encryptedUserMessage += shuffledList.get(list.indexOf(x)) ;
}
System.out.println(letterArray) ;
}
// decrypt the message .
private void decrypt() {
System.out.println("Please send a a message for decryption :") ;
String message = scanner.nextLine() ;
letterArray = message.toCharArray() ;
int i = 0 ;
for (char x : letterArray) {
letterArray[i++] = list.get(shuffledList.indexOf(x)) ;
}
System.out.println(letterArray) ;
}
private void message() {
System.out.printf("Your message before encryption : \"%s\"
" , userMessage) ;
System.out.printf("Your message after encryption : \"%s\"
" , encryptedUserMessage) ;
}
private void load() throws IOException, ClassNotFoundException {
UserInfo userInfo = null ;
// create a file to store you object'sinformation .
FileInputStream fileIn = new FileInputStream("C:\\Users\\wwwha\\eclipse-workspace\\Serializer\\src\\userInfo.ser") ;
ObjectInputStream objectIn = new ObjectInputStream(fileIn) ;
// User class is not recorded in file so we need to cast it as the object type .
userInfo = (UserInfo) objectIn.readObject() ;
fileIn.close() ;
objectIn.close() ;
list = userInfo.list ;
shuffledList = userInfo.shuffledList ;
userMessage = userInfo.userMessage ;
encryptedUserMessage = userInfo.encryptedUserMessage ;
System.out.println("UserInfo loaded .") ;
}
private void quit() throws IOException {
UserInfo userInfo = new UserInfo() ;
userInfo.list = list ;
userInfo.shuffledList = shuffledList ;
userInfo.userMessage = userMessage ;
userInfo.encryptedUserMessage = encryptedUserMessage ;
// create a file to store you object'sinformation .
FileOutputStream fileOut = new FileOutputStream("src/userInfo.ser") ;
ObjectOutputStream objectOut = new ObjectOutputStream(fileOut) ;
objectOut.writeObject(userInfo) ;
fileOut.close() ;
objectOut.close() ;
System.out.println("UserInfo saved .") ;
System.out.println("See you next time .") ;
System.exit(9) ;
}
}
Class : Main
import java.io.IOException;
public class Main {
public static void main(String[] args) throws ClassNotFoundException, IOException {
EncryptionProgram ep = new EncryptionProgram() ;
}
}
Nice tutorial but this is not One-time pad encryption. This is a simple replacement encryption and can be cracked with the proper program and a sufficient large message.
for encrypt method I think it will be better if we wrote it like this:
private void encrypt(){
System.out.print("
Enter a message to be encrypted :");
line = scanner.next();
int lineLength = line.length();
this.letters = new char[lineLength];
for(int i = 0; i < lineLength; i++)
letters[i] = shuffledList.get( list.indexOf( line.charAt(i) ) );
System.out.println("Your encrypted message is :" + String.copyValueOf(letters));
}
and of course for decrypt method it will be the same except we will replace shuffledList with list and list with shuffledList
You actually dont need the list.indexOf part. You could just write:
letters[i] = shuffledList.get(line.charAt(i) - 32);
Since the ASCII character value at index of i in line is 32 ahead of where it positionally is in list/shuffledList. This way, you don't need to hunt thru list to find the index of that character.
@@Clockwerk777 thank you for your comment
I would use 2 shuffled lists and took from each by index in order. It would allow to avoid double letters.
Excellent. Learned a lot. Thank You, Sir
Bro!, You are amazing, I just wanna say Thank you.
Thank you. This helps a lot. Am a beginner at this
so easy and so necessery)
very usefull, thnx
😊😊😊
looks like nobody has noticed the portal reference lol
How do i get the ASCII table to show up in my key? Stuck at 19:44
I think it's showing all the chars on our keyboard
You don't get to print the whole ASCII table. He only prints the printable characters from that table. (32-126). The rest are special characters used by the Operating System.
You should do a GUI version
Once you get the basics of GUI (using other videos on this channel), it's simple to convert this command line code to GUI.
can you please post the GUI version code
may i ask what software you used in this video? for java ofcourse
Eclipse
I find another quicker way to encrypt the message instead of nested loop .
I use the listName.indexOf(element) .
// You can use it with an non-primitive array by changing it to list first .
// Arrays.asList(arrayName).indexOf(element)
private void encrypt() {
System.out.println("Please send a a message for encryption :") ;
String message = scanner.nextLine() ;
letterArray = message.toCharArray() ;
int i = 0 ;
for (char x : letterArray) {
letterArray[i++] = shuffledList.get(list.indexOf(x)) ;
}
System.out.println(letterArray) ; // array cannot be print directly as only string representation will be shown , except char array .
}
Thanks!! this was very helpful.
my bro, thanks for this java tutorial
Nice
Another masterclass bro
My friend, I want to know the basics in order, lesson by lesson, to reach a professional level in java, put it in a post or video, because I completed the data structures, but I am not at the level
You are the best 🙏
I cannot see the code listed in the description as mentioned in the video. I really liked this and did it (well I thought I did) but it will not launch at all. eclipse just says "The Selection cannot be launched, and there are no recent launches." I have not freakin idea what this means or how to fix it. But Thanks anyway. Actually I just fixed it. If anyone else is having this issue and a newbie like me.... select the main java tab (not the Encryption program ) tab and run the java script from there
Wow - I actually got this to work in the end - took me an extra hour to debug my errors and it works well. now I just need to figure our how to convert this same theory into 1 - a GUI and 2 - instead of using ASCII as the code base I want to use the Blockchain BIP39 reference chart
wherre's the code? Bro?
very very awesome🤗
Amazing
thanks for this tuturial
So good to have this video
What a good tutorial thanks!!
my name is in the key that was auto generated at 30:21
GReat
as always the stuff is awesome
Github link for source code please.
i need
can you put the source code? please
have a nice day
Great video.
Thanks you
thank you !
Thanks
Thanks a lot!
Thank youuu
3:28
Best of da best!
I feel like a magician :P
Thanks bro
I wanna donate!
mr hacker donte to whom and for what
very nice!
Thnk u bro
please provide the code in comment
It's in comment but not pinned.
Hello World ;)
Nice video Bro!
java.lang.classnotfoundexception
Solution, professor
Your classpath may be broken, try (in Eclipse):
Run -> Run configurations -> select the class that contains the main() method for your project -> Run
This error occurs when the JVM can't find your class when it compiles
He does not work with me, can I thank you?
Tnx Bro!
Bro why you not post coding in comments 😒
public class Main {
public static void main(String[] args) {
EncryptionProgram ep = new EncryptionProgram();
}
}
************************************************************************************************
import java.util.*;
public class EncryptionProgram {
private Scanner scanner;
private Random random;
private ArrayList list;
private ArrayList shuffledList;
private char character;
private String line;
private char[] letters;
EncryptionProgram(){
scanner = new Scanner(System.in);
random = new Random();
list = new ArrayList();
shuffledList = new ArrayList();
character = ' ';
newKey();
askQuestion();
}
private void askQuestion(){
while(true){
System.out.println("********************************************");
System.out.println("What do you want to do?");
System.out.println("(N)ewKey,(G)etKey,(E)ncrypt,(D)ecrypt,(Q)uit");
char response = Character.toUpperCase(scanner.nextLine().charAt(0));
switch(response){
case 'N':
newKey();
break;
case 'G':
getKey();
break;
case 'E':
encrypt();
break;
case 'D':
decrypt();
break;
case 'Q':
quit();
break;
default:
System.out.println("Not a valid answer :(");
}
}
}
private void newKey(){
character = ' ';
list.clear();
shuffledList.clear();
for(int i=32;i
@@ottttoooo Thanks!!
He has
Hey hope you are doing alright just I wanna say that
GOD loved the world so much he sent his only begotten
son Jesus to die a brutal death for us so that we can have eternal life and we can all accept this amazing gift this by simply trusting in Jesus, confessing that GOD raised him from the dead, turning away from your sins and forming a relationship with GOD.