Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,989 questions

51,934 answers

573 users

How to decrypt a string from numbers to characters in Java

1 Answer

0 votes
public class MyClass {
    private static char convert_to_char_code(String str) {
        int num = Integer.parseInt(str);
        
        return (char)(num + 96);
    }
    
    private static String decrypt(String s) {
    	StringBuilder sb = new StringBuilder();
        
        int i = 0;
        while( i < s.length() - 2) {
            char ch;
            if (s.charAt(i + 2) == '#') {
                ch = (char)convert_to_char_code(s.substring(i, i + 2));
                i += 2;
            } else {
                ch = (char)convert_to_char_code(s.substring(i, i + 1));
            }
            
            i++;
            
            sb.append(ch);
        }

        return sb.toString();
    }
    
    public static void main(String args[]) {
        System.out.print(decrypt("10#1426#25#524#"));
    }
}






/*
run:

jadzyex

*/

 



answered Jul 15, 2023 by avibootz

Related questions

1 answer 122 views
1 answer 66 views
1 answer 116 views
1 answer 125 views
1 answer 146 views
1 answer 69 views
...