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
@chase_exists42992 жыл бұрын
I think you should pin the message bro
@BilalAkhtar-m7o3 ай бұрын
No randaom use in whole code .😢
@riseofkingdoms24693 жыл бұрын
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!!!!
@winterSweet-k4m4 жыл бұрын
just found this channel by accident, subscribed without a hesitation. keep up with the UNIQUE and WHOLESOME work man!
@radusimonica55503 жыл бұрын
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.
@Michel-dx1bn2 жыл бұрын
You have such a hacker brain :)
@andromydous2 жыл бұрын
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.
@sounavamandal9f2232 жыл бұрын
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
@stephaniepanah13872 жыл бұрын
Strains of, Car car equals new car, and, Dog dog equals new dog, keep rolling through my head. good job. thank you
@AHMED_PROGRAMMING Жыл бұрын
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)); }
@AHMED_PROGRAMMING Жыл бұрын
and of course for decrypt method it will be the same except we will replace shuffledList with list and list with shuffledList
@Clockwerk7779 ай бұрын
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.
@AHMED_PROGRAMMING9 ай бұрын
@@Clockwerk777 thank you for your comment
@maxwong17682 жыл бұрын
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() ; } }
@11d7th Жыл бұрын
Program complete. This walkthrough is golden. Thanks, Bro!
@kxnyshk3 жыл бұрын
man! this was so cool and easy to learn! Thanks for this :) 💜
@DanielSmith-uj7rr3 жыл бұрын
Awesome. Thank you Bro! This project is very useful. The way you teach is just AWESOME!
@TyyylerDurdenАй бұрын
I would use 2 shuffled lists and took from each by index in order. It would allow to avoid double letters.
@AHMED_PROGRAMMING Жыл бұрын
7:27 🤔Why we declared "random" and initialized but didn't use it ?
@MyBoatHasAFlatTireАй бұрын
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.
@maxwong17682 жыл бұрын
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 . }
@jordanguada43544 жыл бұрын
thanks man, gonna use this skill for my upcoming internship!
@ΒαγγΣτανιος4 жыл бұрын
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.
@meksudbuser9624 Жыл бұрын
Bro!, You are amazing, I just wanna say Thank you.
@roryodonoghue32863 жыл бұрын
Excellent. Learned a lot. Thank You, Sir
@furkanyldz02 ай бұрын
looks like nobody has noticed the portal reference lol
@desmiles15673 жыл бұрын
Another masterclass bro
@rodelioliwag76272 жыл бұрын
Thank you. This helps a lot. Am a beginner at this
@Geno4202 жыл бұрын
my bro, thanks for this java tutorial
@joecucco41322 жыл бұрын
How do i get the ASCII table to show up in my key? Stuck at 19:44
@riyamandal76672 жыл бұрын
I think it's showing all the chars on our keyboard
@GKirChhOff2 жыл бұрын
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.
@McMeil3 жыл бұрын
so easy and so necessery) very usefull, thnx
@rent2ownnz Жыл бұрын
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
@rent2ownnz Жыл бұрын
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
@alhabib3031a Жыл бұрын
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
@kingcrashplays3 жыл бұрын
You should do a GUI version
@aliasgharkhoyee95013 жыл бұрын
Once you get the basics of GUI (using other videos on this channel), it's simple to convert this command line code to GUI.
@sacmarv89972 жыл бұрын
can you please post the GUI version code
@alooyeg3 жыл бұрын
my name is in the key that was auto generated at 30:21
@michaelayo23 жыл бұрын
wherre's the code? Bro?
@kurtdecena8681 Жыл бұрын
may i ask what software you used in this video? for java ofcourse
@mehrdadaria8711 Жыл бұрын
Eclipse
@nehalayaaz94064 жыл бұрын
You are the best 🙏
@it04ameekanazreen592 жыл бұрын
Thanks!! this was very helpful.
@abdelkaderouhssain32432 жыл бұрын
What a good tutorial thanks!!
@eugenezuev73495 ай бұрын
as always the stuff is awesome
@subhashree88873 жыл бұрын
So good to have this video
@sreeshakv54052 жыл бұрын
Nice
@mahdib93614 жыл бұрын
Amazing thanks for this tuturial
@ah1122bi4 жыл бұрын
can you put the source code? please
@kemann38153 жыл бұрын
Best of da best!
@murrayKorir3 жыл бұрын
very very awesome🤗
@zari_7232 жыл бұрын
have a nice day
@erfan_rad2 жыл бұрын
Github link for source code please.
@aliit72422 жыл бұрын
i need
@pconairofficial43332 жыл бұрын
GReat
@rke40072 жыл бұрын
3:28
@pejko892 жыл бұрын
I feel like a magician :P
@anonimanonim12232 жыл бұрын
Great video.
@Mrcodeuniverse4 ай бұрын
😊😊😊
@gerhardmorozov66133 жыл бұрын
Nice video Bro!
@sewek15132 жыл бұрын
Thanks a lot!
@nawfalnjm56993 жыл бұрын
thank you !
@robertzdeb81033 жыл бұрын
very nice!
@MrLoser-ks2xn2 жыл бұрын
Thanks
@skillR-2433 жыл бұрын
Thanks you
@MrLoser-ks2xn Жыл бұрын
@muhammadamir97993 жыл бұрын
please provide the code in comment
@aruldilip94303 жыл бұрын
It's in comment but not pinned.
@zainabfahim61702 жыл бұрын
Thank youuu
@aliasqar5379 Жыл бұрын
Hello World ;)
@kamoshira Жыл бұрын
Thanks bro
@tonalddrump93914 жыл бұрын
I wanna donate!
@srinicnu52833 жыл бұрын
mr hacker donte to whom and for what
@chamodmaduwantha57763 жыл бұрын
Thnk u bro
@signx32872 жыл бұрын
Tnx Bro!
@MO-dd3cs4 жыл бұрын
java.lang.classnotfoundexception Solution, professor
@BroCodez4 жыл бұрын
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
@MO-dd3cs4 жыл бұрын
He does not work with me, can I thank you?
@gautamsharma3143 жыл бұрын
Bro why you not post coding in comments 😒
@ottttoooo3 жыл бұрын
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
@howong85613 жыл бұрын
@@ottttoooo Thanks!!
@rachelgreen9754 Жыл бұрын
He has
@zstar8397 Жыл бұрын
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.