Need Help Reversing my Encryption Algorithm So I wrote a simple encryption algorithm (Not very secure, just a starting point. I don't want criticism on it.) and I have been having trouble finding a way to decrypt the text. The algorithm is here (You may need an ASCII table to understand it):

Key = key
DecimalKey: k + e + y = 107 + 101 + 121 = 329 / 3(Length of actual key) = 110
Each Char: (charDec * keyLength) - DecimalKey

Example: p (112 * 3 = 336) - 110 = 226


Then I would subtract 127 from 226 so it will correspond to ASCII (this will be checked each time with an if statement).

My Java implementation of this is below (Hopefully code is allowed?):

public static String encrypt(String str, String key) {
    String encrypted = "";        
    char[] strChars = new char[str.length()];
    char[] keyChars = new char[key.length()];        
    int[] strDecs = new int[strChars.length];
    int[] keyDecs = new int[keyChars.length];        
    int[] strPDecs = new int[strDecs.length];        
    int keyNum = 0;        
    for(int i = 0; i &lt; str.length(); i++) {
        strChars[i] = str.charAt(i);
    }
    for(int i = 0; i &lt; key.length(); i++) {
        keyChars[i] = key.charAt(i);
    }
    for(int i = 0; i &lt; strDecs.length; i++) {
        strDecs[i] = Integer.valueOf((char)strChars[i]);
    }
    for(int i = 0; i &lt; keyDecs.length; i++) {
        keyDecs[i] = Integer.valueOf((char)keyChars[i]);
    }        
    for(int i : keyDecs) {
        keyNum += i;
    }
    float fTempKeyNum = keyNum;
    fTempKeyNum /= keyChars.length;
    keyNum = Math.round(fTempKeyNum);        
    for(int i = 0; i &lt; strDecs.length; i++) {
        strPDecs[i] = (strDecs[i] * keyChars.length) - keyNum;
        while(strPDecs[i] &gt; 126) {
            strPDecs[i] -= 127;
        }
        while(strPDecs[i] &lt; 0) {
            strPDecs[i] = 127 - Math.abs(strPDecs[i]);
        }
        if(strPDecs[i] &lt; 32) {
            strPDecs[i] = 126 - Math.abs(strPDecs[i]);
        }
    }        
    for(int i : strPDecs) {
        encrypted += Character.toString((char) i);
    }
    return encrypted;
}


So can someone help me find a way to reverse this algorithm? Sorry if I got some terms wrong, as I am quite new to Cryptography. If more explanation is required I can probably post a bit more.
Unfortunately, you have created an un-invertible cipher, that is why you can't decrypt it.


  Then I would subtract 127 from 226 so it will correspond to ASCII


Since you do charDec * keyLength this will not work when the key is longer (Imagine a 10 char key, you would get 1120 as your intermediate result, you won't get this back into ASCII range with your final subtraction).

So what you would need is to take your result modulo 256 (or modulo 127 if you want to stay in the ASCII range).
But then your scheme will basically amount to a % b = c, where to decrypt you have to recompute a, from b and c. There is an infinite number of solutions. You cannot decrypt.

You could study the design and internal operations of an existing cipher like DES, to see how they achieve invertibility and confusion at the same time.