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_exists4299
2 жыл бұрын
I think you should pin the message bro
@BilalAkhtar-m7o
Ай бұрын
No randaom use in whole code .😢
@riseofkingdoms2469
3 жыл бұрын
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-k4m
4 жыл бұрын
just found this channel by accident, subscribed without a hesitation. keep up with the UNIQUE and WHOLESOME work man!
@radusimonica5550
3 жыл бұрын
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-dx1bn
2 жыл бұрын
You have such a hacker brain :)
@andromydous
2 жыл бұрын
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.
@sounavamandal9f223
Жыл бұрын
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
@kxnyshk
3 жыл бұрын
man! this was so cool and easy to learn! Thanks for this :) 💜
@DanielSmith-uj7rr
3 жыл бұрын
Awesome. Thank you Bro! This project is very useful. The way you teach is just AWESOME!
@maxwong1768
2 жыл бұрын
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() ; } }
@stephaniepanah1387
2 жыл бұрын
Strains of, Car car equals new car, and, Dog dog equals new dog, keep rolling through my head. good job. thank you
@11d7th
Жыл бұрын
Program complete. This walkthrough is golden. Thanks, Bro!
@meksudbuser9624
Жыл бұрын
Bro!, You are amazing, I just wanna say Thank you.
@jordanguada4354
3 жыл бұрын
thanks man, gonna use this skill for my upcoming internship!
@roryodonoghue3286
3 жыл бұрын
Excellent. Learned a lot. Thank You, Sir
@maxwong1768
2 жыл бұрын
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 . }
@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
@Clockwerk777
7 ай бұрын
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_PROGRAMMING
7 ай бұрын
@@Clockwerk777 thank you for your comment
@rodelioliwag7627
Жыл бұрын
Thank you. This helps a lot. Am a beginner at this
@ΒαγγΣτανιος
3 жыл бұрын
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.
@McMeil
3 жыл бұрын
so easy and so necessery) very usefull, thnx
@AHMED_PROGRAMMING
Жыл бұрын
7:27 🤔Why we declared "random" and initialized but didn't use it ?
@Geno420
2 жыл бұрын
my bro, thanks for this java tutorial
@desmiles1567
2 жыл бұрын
Another masterclass bro
@it04ameekanazreen59
Жыл бұрын
Thanks!! this was very helpful.
@nehalayaaz9406
4 жыл бұрын
You are the best 🙏
@abdelkaderouhssain3243
2 жыл бұрын
What a good tutorial thanks!!
@eugenezuev7349
4 ай бұрын
as always the stuff is awesome
@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
@mahdib9361
3 жыл бұрын
Amazing thanks for this tuturial
@kemann3815
2 жыл бұрын
Best of da best!
@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
@furkanyldz0
25 күн бұрын
looks like nobody has noticed the portal reference lol
@subhashree8887
3 жыл бұрын
So good to have this video
@kurtdecena8681
Жыл бұрын
may i ask what software you used in this video? for java ofcourse
@mehrdadaria8711
Жыл бұрын
Eclipse
@murrayKorir
2 жыл бұрын
very very awesome🤗
@anonimanonim1223
2 жыл бұрын
Great video.
@sewek1513
2 жыл бұрын
Thanks a lot!
@kingcrashplays
3 жыл бұрын
You should do a GUI version
@aliasgharkhoyee9501
3 жыл бұрын
Once you get the basics of GUI (using other videos on this channel), it's simple to convert this command line code to GUI.
@sacmarv8997
2 жыл бұрын
can you please post the GUI version code
@gerhardmorozov6613
3 жыл бұрын
Nice video Bro!
@pejko89
2 жыл бұрын
I feel like a magician :P
@robertzdeb8103
3 жыл бұрын
very nice!
@nawfalnjm5699
3 жыл бұрын
thank you !
@pconairofficial4333
2 жыл бұрын
GReat
@sreeshakv5405
2 жыл бұрын
Nice
@Ahmadshajahan-hn7jp
2 ай бұрын
😊😊😊
@michaelayo2
2 жыл бұрын
wherre's the code? Bro?
@zainabfahim6170
Жыл бұрын
Thank youuu
@ah1122bi
3 жыл бұрын
can you put the source code? please
@kamoshira
Жыл бұрын
Thanks bro
@skillR-243
3 жыл бұрын
Thanks you
@signx3287
2 жыл бұрын
Tnx Bro!
@alooyeg
3 жыл бұрын
my name is in the key that was auto generated at 30:21
@MrLoser-ks2xn
2 жыл бұрын
Thanks
@erfanakhavanrad6597
2 жыл бұрын
Github link for source code please.
@aliit7242
2 жыл бұрын
i need
@chamodmaduwantha5776
2 жыл бұрын
Thnk u bro
@joecucco4132
2 жыл бұрын
How do i get the ASCII table to show up in my key? Stuck at 19:44
@riyamandal7667
2 жыл бұрын
I think it's showing all the chars on our keyboard
@GKirChhOff
2 жыл бұрын
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.
@zari_723
Жыл бұрын
have a nice day
@muhammadamir9799
3 жыл бұрын
please provide the code in comment
@aruldilip9430
2 жыл бұрын
It's in comment but not pinned.
@tonalddrump9391
3 жыл бұрын
I wanna donate!
@srinicnu5283
3 жыл бұрын
mr hacker donte to whom and for what
@rke4007
2 жыл бұрын
3:28
@aliasqar5379
Жыл бұрын
Hello World ;)
@MrLoser-ks2xn
Жыл бұрын
@MO-dd3cs
4 жыл бұрын
java.lang.classnotfoundexception Solution, professor
@BroCodez
4 жыл бұрын
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-dd3cs
4 жыл бұрын
He does not work with me, can I thank you?
@gautamsharma314
3 жыл бұрын
Bro why you not post coding in comments 😒
@ottttoooo
3 жыл бұрын
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
@howong8561
2 жыл бұрын
@@ottttoooo Thanks!!
@rachelgreen9754
Жыл бұрын
He has
@zstar8397
11 ай бұрын
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.
Пікірлер: 85