ElectricTuna.exe's Profile User Rating: -----

Reputation: 1 Apprentice
Group:
Members
Active Posts:
23 (0.03 per day)
Joined:
02-September 12
Profile Views:
182
Last Active:
User is offline Oct 23 2012 02:21 AM
Currently:
Offline

Previous Fields

Dream Kudos:
0
Icon   ElectricTuna.exe has not set their status

Posts I've Made

  1. In Topic: Casting ints into chars

    Posted 22 Oct 2012

    @jon:

    Thanks for all of your input, I appreciate it, but...It's not quite what I needed. I don't understand how implementing modulus here really accomplishes anything. It's ok, though, because I solved my own problem:

        StringBuilder sb = new StringBuilder();
        String a = "";
        int encodeVal = 0;
        char c = 0;
            for (int i = 0; i < str.length(); i++){
                encodeVal = (int)str.charAt(i) + key;
                c = (char)encodeVal;
                sb.append(c);
                a = sb.toString();
            }
        System.out.println(a);
        }
    
    


    For some reason, this works. I guess I didn't need the additional for loop. Anyway, I may be able to use modulus to set a predetermined range for each character in the ASCII table, such that values for the key will generate output that'll omit certain characters by value...

    ...or something.
  2. In Topic: Casting ints into chars

    Posted 22 Oct 2012

    Logical Operators...

    You mean (<) less than, (>) greater than, (<=) less than or equal to, (>=) greater than or equal to, (!=) is not equal to, (&&) and, (||) or, and (^) exclusive to, right?

    How exactly does this help? If I say something like:

    int aNum = 0;
    if(aNum <=25){
    //DO_SOMETHING
    }

    that's a conditional statement. Meaning, you're telling the compiler to "skip rocks" or "jump through a hoop of fire" every time "aNum" is charged with a value that is less than or equal to 25. If it is passed a value that is greater than 25, then the block of code won't execute...
  3. In Topic: Casting ints into chars

    Posted 22 Oct 2012

    If I understand correctly, you're saying that if you started counting from zero at A, and you added 1 to every subsequent number, you'd essentially count over and over and until you reach the desired destination which, in this case, would be 25, right?

    A = 0;
    B = 1;
    C = 2;
    D = 3;

    etc...


    Adding, or incrementing your counter. Right?
  4. In Topic: Casting ints into chars

    Posted 22 Oct 2012

    @pbl:

    I tried what you suggested like this:

        public void encode(){
        StringBuilder sb = new StringBuilder();
        String a = "";
        int encodeVal = 0;
        char c = 0;
            for (int i = 0; i < str.length(); i++){
                encodeVal = (int)str.charAt(i) + key;
            }
            for(int i = 0; i < str.length(); i++){
                c = (char)(encodeVal - key);
                sb.append(c);
                a = sb.toString();
            }
    
    


    And my output on the console came out like this (after testing lowercase 'green'):

    nnnnn

    The problem is (1) if I subtract "key" from "encodeVal" I end up with the same values that I originally started with. That's not what I need. I need to make 'green' + a randomly generated number = a random set of characters stringed together, so that the output looks something like this:

    @#%$^

    That is just an example; I know that the output will vary depending on the value of "key", but for the purposes of this conversation, that example should suffice. (2) I need to append every character into the stringbuilder object so that my output isn't the last character in the string over and over again. My output was "nnnnn" after I did what you suggested, which is basically writing the last character of the for-loop's execution into the stringbuilder and displaying it to the user.

    @jon:

    You're talking about subtraction, of course. If you have something like:

    String alphaChars = "A, B, C, ...X, Y, Z";
    String[] anArray = new String[alphaChars];
    for(int 1 = 0; i < anArray; i++){
         String holdMyChars = anArray.charAt(i);
         System.out.println(holdMyChars);
    }
    
    


    and you don't subtract 1 from the (i), when you try to access, say 'A' by calling
    i = 1, you'll end getting B instead because every array starts indexed at zero.
  5. In Topic: Casting ints into chars

    Posted 22 Oct 2012

    The output is going to be placed in a JTextField. From there, the user will decide what they want to do. They can either append the data to a file named "Enigma", get rid of it completely, or re-enter it and decode it once more.

    I want to take the string or document initially inserted for encryption, convert each char into it's associated value, alter this value by adding it to the key, and then taking this newly altered value and converting it back into a char which will be placed into a string and displayed to the user via a jTextArea.

    I guess alphabetical characters would be the most accurate response. It's pseudo encryption, so the output should be garbled. Then, if the user wants to decode it, they enter the key and it should revert back to the original text.

My Information

Member Title:
New D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:

Contact Information

E-mail:
Private

Friends

ElectricTuna.exe hasn't added any friends yet.

Comments

ElectricTuna.exe has no profile comments yet. Why not say hello?