java - take hex character, insert random character after it, take second hex character and insert another random character -
i'm new programming, , 1 has me scratching head.
well, more banging head.
the idea of program take input, convert ascii, hex, create random character, insert after first hex character, take second hex character, , insert random character after second hex character.
such like: randchar1 + 1st char of hexstring + randchar2 + 2nd char of hexstring
for example,
the hex code "asdf" 61736466. need seperate 61 group, insert random characters i.e. "r,u" in such way displays "6r1u" first , 3rd characters 1 single hex code. i'm not quite sure how since strings immutable, , i'm stuck ridiculous. i've searched hundreds of forums, literally, , have yet come accross 1 specific question is.
aside inserting random characters, need take new string consisting of 4 characters, , iterate through each hex code, have no idea how do.
i.e.
take 61, add random characters @ index 1 , 3, take 73, repeat adding characters, , length of word.
i absolutely stumped on how this, it's incredibly frustrating sitting here trying figure out when havent slightest clue.
i'm sorry if i'm not wording or making sound confusing.
this pseudocode given our professor, have made many modifications, none of code final , half of still pseudocode.
again, apologies if terrible wording , format, it's first post. i'm concerned getting encryption working, i'm not worried decryption @ point.
it wonderful if point me in right direction, write code enables program achieve degree:
(randchar1 + 1st char of hexstring + randchar2 + 2nd char of hexstring): gives me 4 character string consisting of 1 hex code. break each double digit hex , in between add random characters, , iterate through each hex code, adding random letters in same fashion @ indexes 2 , 4, until hex code has been converted 4 character "encrypted" string
/* * change license header, choose license headers in project properties. * change template file, choose tools | templates * , open template in editor. */ package encryptionprogram; import java.util.random; import java.util.scanner; /** * * @author elliott cade */ public class encryptionprogram { public static void main(string[] args) { // todo code application logic here scanner sc = new scanner(system.in); string plaintext, encryptedtext, decryptedtext, asciivalue, ascii; system.out.print("enter message: "); plaintext = sc.nextline(); //takes user input asciivalue= plaintext; system.out.println(); system.out.println("encrypted message"); encryptedtext = encryptcharacter(asciivalue); system.out.println(encryptedtext); //disregard system.out.println(); system.out.println("decrypted message:"); decryptedtext = decryptmessage(encryptedtext); //disregard system.out.println(decryptedtext); ascii = encryptcharacter(asciivalue); } public static string encryptmessage(string plaintext) { encryptedmsg = { //disregard } { encryptedchar = encryptcharacter(plaintext.charat(i)); encryptedmsg = encryptedmsg + encryptedchar; } return encryptedmsg } public static string decryptmessage(string encryptedtext) { string decryptedmsg,encryptedletter; decryptedmsg = “” each group of 4 characters character in encryptedtext { encryptedletter = encryptedtext.substring 4 characters decryptedchar = decryptcharacter(encryptedletter); encryptedmsg = encryptedmsg + decryptedchar; } return decryptedmsg; } private static string encryptcharacter(string asciivalue) { char[] chars = asciivalue.tochararray(); stringbuilder hex = new stringbuilder(); (int = 0; < chars.length; i++) //takes input , converts hex format hex.append(integer.tohexstring((int) chars[i])); system.out.println(); { } return hex.tostring(); } public static char decryptcharacter(string encryptedcharacter) { // need implement function decryptedchar = char1 + char3 asciicode = convert hexadecimal decryptedchar ascii decimal code decryptedchar = convert ascii code character return decryptedchar; }
}
use stringbuilder
.
for (int = 0; < str.length(); i++) { char = (char) rand.nextint(range); sb.append(str.charat(i)); sb.append(a); } return sb.tostring();
change rand.nextint()
fit range of characters want.