Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!

F Lucas

Greenhorn
+ Follow
since Jul 04, 2017
Cows and Likes
Cows
Total received
2
In last 30 days
2
Total given
0
Likes
Total received
1
Received in last 30 days
1
Total given
3
Given in last 30 days
3
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by F Lucas

Campbell Ritchie wrote:That looks a very complicated way to look for numbers, particularly when you have been provided with a reliable and well‑tried technique.


I just wanted to give an answer that accepts any amount of inputs. OP did not specify how many numbers he wants to calculate.
21 hours ago
You need to atleast tell us what you want to do. If you just post like that with no context people will think you are just lazy and not trying.
1 day ago
Want a quick answer?
When to use getters and setters? almost always.
When to use inheritance? Java lets you build programs from outside to the inside, instead from bottom
to the top. This helps maintaining and updating code easier. Inheritance is one of the ways java achieves that. For example....
Theres a class movableCharacter.
You can make a class npc that has his move() method replaced by an AI, and a class player
that uses the input scanner of his class to move.
Why is this important? Because you can say Object.move() and it wont matter if it is an npc object or a player object and it will still move with no errors.
1 day ago
I would do this to ensure fool-proof.  
Print "Please input numbers, and input "calculate" to calculate the average."
1. Get an input scanner.
2. Initialize a boolean "breakRequested" and "notDigit" as false
3. Initialize arrayList of ints
4. While breakRequested is false, if input.equals("calculate") is not true
5. for(char c :input.toCharArray()){
6. if c.isDigit()
7. Nothing
8. Else notDigit = true and break;
9. if notdigit is false
10. add input.parseInt to the arraylist
11. Else print "please input only numbers."
and if the input equals calculate is true you set breakRequested to true and break. It ends the loop.
Probably not the best answer. I did not actually write the code to see if it is practical, but I hope
it helps.

1 day ago
Thank you Stephan. After changing the methods and double checking everything, I noticed a few things.
And it now works!
I will leave everything I did to make it work here.
1. I was only saving the value from .doFinal() and that was wrong.
FIX: Use .update() first, save into an array, and concatenate the two arrays with arraycopy.
2. Apparently When using base64 and encryption together, encoding first is wrong.
FIX: Encrypt first, then encode. Then decode before decrypting.
3. No more inconsistencies on the input and output. But now it gave me a tag mismatch error.
FIX: I had to extract the authentication tag (16 bytes in the end of the ciphertext) and use .doFinal
with it as parameter to make it verify the tag.
I learned a lot from debugging this. Again, thank you for the tips.  
I hope you have a VERY nice day!
1 day ago
Thanks for the reply. Just one more thing. Does it mean I have to
Export all the formatting code to a separate method
Make the method symmetric, and make it accept a parameter to change between encryption mode and decryption mode
Polish the code more
And print out the Key, salt, and ciphertext in Base64 for debug purposes
Am I correct? I just wanted to make it sure before starting to work on it.
Thanks in advance.
Edit : I use excessive amounts of comments on my code because it helps me remember basic code. But it probably reduces readability, so I will omit it next time.
2 weeks ago
I changed my encription algorythm to AES.
Also improved code readability.
There is a lot of unexplicably hardcoded sections on the encryption, but it is because I am scared of changing anything and it suddently stop working.  
I just want to get it to work, so I can then improve it later.  
Also I don't quite understand the keyspecs, so most of it are copy-pasted.  
This time, I started getting a badtag exception. It encrypts fine, but when decrypting it tells me that it had a tag mismatch.  
If anybody could help me I would be grateful.


2 weeks ago
Thanks to both of you for the reply.  
I will repost this after I change algorythms and make my code more visible.  
Should I do it in another post or just use the reply?
3 weeks ago
Hello! I have been working on a Employee management system for practice, and after making the core classes, I thought of encrypting the data.  
The problem is, every single place I search talks about symmetrical, one-time encryption and decryption, using the same salt for both and doing it in one run.  
But I want to save it for later use! And I am really lost at EVERYTHING of this. Every help is appreciated, but here are a list of the biggest problems right now.
  • UTF-8 Leaves 3 bytes of data, making it difficult to read the salt. What do I do?
  • Saving happens just fine, but the decryption is not working at the moment.
  • Should I save in bytes or in string? And what is the right way to convert byte to string and vice-versa?

  • Here is the part of my code that handles this.
    (Please ignore the comments. Most of them is for me to not forget what everything does.)
    My localGetter class, that implements getter. Responsible for retrieving and saving data.  

    Thanks in advance.
    3 weeks ago
    Hello, this is my first time here.
    I was making a Java program as an exercise, which is like a little Vehicle Simulator. And there is an method where,
    1. It generates a random number with the name "Tempinitial"
    2. It checks if "Tempinitial" is the same as "Initial"
    3. If it is, it regenerates the number with the exception of the number assigned to "Initial"
    4. Else, it will just set the number from "Tempinitial" to "Initial"
    5. When you go check the Color, it will set the "PaintColor" to a color (a string that represents a color, like "Red") depending on which number it is.
    But I'm having problems in step 1, because it always uses the default case even though it can use the case 1.
    Please help me.  

    the code:



         
           
         
                 
       

    1 year ago