Java encryption program 🔑

  Рет қаралды 47,417

Bro Code

Bro Code

Күн бұрын

Пікірлер: 87
@BroCodez
@BroCodez 4 жыл бұрын
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
@chase_exists4299 2 жыл бұрын
I think you should pin the message bro
@BilalAkhtar-m7o
@BilalAkhtar-m7o 3 ай бұрын
No randaom use in whole code .😢
@riseofkingdoms2469
@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
@winterSweet-k4m 4 жыл бұрын
just found this channel by accident, subscribed without a hesitation. keep up with the UNIQUE and WHOLESOME work man!
@radusimonica5550
@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
@Michel-dx1bn 2 жыл бұрын
You have such a hacker brain :)
@andromydous
@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
@sounavamandal9f223 2 жыл бұрын
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
@stephaniepanah1387
@stephaniepanah1387 2 жыл бұрын
Strains of, Car car equals new car, and, Dog dog equals new dog, keep rolling through my head. good job. thank you
@AHMED_PROGRAMMING
@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
@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
@Clockwerk777 9 ай бұрын
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
@AHMED_PROGRAMMING 9 ай бұрын
@@Clockwerk777 thank you for your comment
@maxwong1768
@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() ; } }
@11d7th
@11d7th Жыл бұрын
Program complete. This walkthrough is golden. Thanks, Bro!
@kxnyshk
@kxnyshk 3 жыл бұрын
man! this was so cool and easy to learn! Thanks for this :) 💜
@DanielSmith-uj7rr
@DanielSmith-uj7rr 3 жыл бұрын
Awesome. Thank you Bro! This project is very useful. The way you teach is just AWESOME!
@TyyylerDurden
@TyyylerDurden Ай бұрын
I would use 2 shuffled lists and took from each by index in order. It would allow to avoid double letters.
@AHMED_PROGRAMMING
@AHMED_PROGRAMMING Жыл бұрын
7:27 🤔Why we declared "random" and initialized but didn't use it ?
@MyBoatHasAFlatTire
@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.
@maxwong1768
@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 . }
@jordanguada4354
@jordanguada4354 4 жыл бұрын
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
@meksudbuser9624 Жыл бұрын
Bro!, You are amazing, I just wanna say Thank you.
@roryodonoghue3286
@roryodonoghue3286 3 жыл бұрын
Excellent. Learned a lot. Thank You, Sir
@furkanyldz0
@furkanyldz0 2 ай бұрын
looks like nobody has noticed the portal reference lol
@desmiles1567
@desmiles1567 3 жыл бұрын
Another masterclass bro
@rodelioliwag7627
@rodelioliwag7627 2 жыл бұрын
Thank you. This helps a lot. Am a beginner at this
@Geno420
@Geno420 2 жыл бұрын
my bro, thanks for this java tutorial
@joecucco4132
@joecucco4132 2 жыл бұрын
How do i get the ASCII table to show up in my key? Stuck at 19:44
@riyamandal7667
@riyamandal7667 2 жыл бұрын
I think it's showing all the chars on our keyboard
@GKirChhOff
@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.
@McMeil
@McMeil 3 жыл бұрын
so easy and so necessery) very usefull, thnx
@rent2ownnz
@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
@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
@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
@kingcrashplays
@kingcrashplays 3 жыл бұрын
You should do a GUI version
@aliasgharkhoyee9501
@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
@sacmarv8997 2 жыл бұрын
can you please post the GUI version code
@alooyeg
@alooyeg 3 жыл бұрын
my name is in the key that was auto generated at 30:21
@michaelayo2
@michaelayo2 3 жыл бұрын
wherre's the code? Bro?
@kurtdecena8681
@kurtdecena8681 Жыл бұрын
may i ask what software you used in this video? for java ofcourse
@mehrdadaria8711
@mehrdadaria8711 Жыл бұрын
Eclipse
@nehalayaaz9406
@nehalayaaz9406 4 жыл бұрын
You are the best 🙏
@it04ameekanazreen59
@it04ameekanazreen59 2 жыл бұрын
Thanks!! this was very helpful.
@abdelkaderouhssain3243
@abdelkaderouhssain3243 2 жыл бұрын
What a good tutorial thanks!!
@eugenezuev7349
@eugenezuev7349 5 ай бұрын
as always the stuff is awesome
@subhashree8887
@subhashree8887 3 жыл бұрын
So good to have this video
@sreeshakv5405
@sreeshakv5405 2 жыл бұрын
Nice
@mahdib9361
@mahdib9361 4 жыл бұрын
Amazing thanks for this tuturial
@ah1122bi
@ah1122bi 4 жыл бұрын
can you put the source code? please
@kemann3815
@kemann3815 3 жыл бұрын
Best of da best!
@murrayKorir
@murrayKorir 3 жыл бұрын
very very awesome🤗
@zari_723
@zari_723 2 жыл бұрын
have a nice day
@erfan_rad
@erfan_rad 2 жыл бұрын
Github link for source code please.
@aliit7242
@aliit7242 2 жыл бұрын
i need
@pconairofficial4333
@pconairofficial4333 2 жыл бұрын
GReat
@rke4007
@rke4007 2 жыл бұрын
3:28
@pejko89
@pejko89 2 жыл бұрын
I feel like a magician :P
@anonimanonim1223
@anonimanonim1223 2 жыл бұрын
Great video.
@Mrcodeuniverse
@Mrcodeuniverse 4 ай бұрын
😊😊😊
@gerhardmorozov6613
@gerhardmorozov6613 3 жыл бұрын
Nice video Bro!
@sewek1513
@sewek1513 2 жыл бұрын
Thanks a lot!
@nawfalnjm5699
@nawfalnjm5699 3 жыл бұрын
thank you !
@robertzdeb8103
@robertzdeb8103 3 жыл бұрын
very nice!
@MrLoser-ks2xn
@MrLoser-ks2xn 2 жыл бұрын
Thanks
@skillR-243
@skillR-243 3 жыл бұрын
Thanks you
@MrLoser-ks2xn
@MrLoser-ks2xn Жыл бұрын
@muhammadamir9799
@muhammadamir9799 3 жыл бұрын
please provide the code in comment
@aruldilip9430
@aruldilip9430 3 жыл бұрын
It's in comment but not pinned.
@zainabfahim6170
@zainabfahim6170 2 жыл бұрын
Thank youuu
@aliasqar5379
@aliasqar5379 Жыл бұрын
Hello World ;)
@kamoshira
@kamoshira Жыл бұрын
Thanks bro
@tonalddrump9391
@tonalddrump9391 4 жыл бұрын
I wanna donate!
@srinicnu5283
@srinicnu5283 3 жыл бұрын
mr hacker donte to whom and for what
@chamodmaduwantha5776
@chamodmaduwantha5776 3 жыл бұрын
Thnk u bro
@signx3287
@signx3287 2 жыл бұрын
Tnx Bro!
@MO-dd3cs
@MO-dd3cs 4 жыл бұрын
java.lang.classnotfoundexception Solution, professor
@BroCodez
@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
@MO-dd3cs 4 жыл бұрын
He does not work with me, can I thank you?
@gautamsharma314
@gautamsharma314 3 жыл бұрын
Bro why you not post coding in comments 😒
@ottttoooo
@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
@howong8561 3 жыл бұрын
@@ottttoooo Thanks!!
@rachelgreen9754
@rachelgreen9754 Жыл бұрын
He has
@zstar8397
@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.
Java text editor app 📓
39:35
Bro Code
Рет қаралды 69 М.
Password Storage Tier List: encryption, hashing, salting, bcrypt, and beyond
10:16
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 47 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 46 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 691 М.
Java generics ❓
22:04
Bro Code
Рет қаралды 119 М.
AES: How to Design Secure Encryption
15:37
Spanning Tree
Рет қаралды 176 М.
Cryptography 101 for Java developers by Michel Schudel
42:59
Encryption program in Python 🔐
8:41
Bro Code
Рет қаралды 133 М.
Java HashMap 🗺️
13:05
Bro Code
Рет қаралды 91 М.
Java lambda λ
18:00
Bro Code
Рет қаралды 99 М.
7 Cryptography Concepts EVERY Developer Should Know
11:55
Fireship
Рет қаралды 1,4 МЛН
For Loop Pattern Program In Java #25
15:49
Alex Lee
Рет қаралды 171 М.
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 407 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 47 МЛН