litesoft
@ HEAD
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.encryption.symmetric; import org.litesoft.commonfoundation.base.*; public class BrainDeadSymmetricEncryptor extends AbstractSymmetricEncryptor { public static final SymmetricEncryptor INSTANCE = new BrainDeadSymmetricEncryptor(); public String getIdentifierAndVersion() { return "BDSE-1"; } protected Helper createHelper( String pText ) { return new MyHelper( pText ); } private static class MyHelper extends Helper { public MyHelper( String pText ) { super( pText ); } public String done() { return toString(); } public void encode( int pChar ) { if ( (pChar == ' ') || (('a' <= pChar) && (pChar <= 'z')) ) { mSB.append( (char) encodeAlpha( pChar, 0 ) ); return; } if ( ('A' <= pChar) && (pChar <= 'Z') ) { mSB.append( (char) encodeAlpha( pChar + ASCII_CASE_DELTA, 46 ) ); return; } int at = OTHER_SRC.indexOf( pChar ); if ( at != -1 ) { mSB.append( ALPHA_SRC.charAt( at ) ); mLastIndexIntoAS = at; return; } mSB.append( (char) 96 ); char[] zDigits = Hex.to4Chars( (char) pChar ); for ( char zDigit : zDigits ) { encode( zDigit ); } } private int encodeAlpha( int pChar, int pReturnOffset ) { int at = ALPHA_SRC.indexOf( pChar, mLastIndexIntoAS + 1 ); if ( at == -1 ) { pReturnOffset += ALPHA_SRC.length() - mLastIndexIntoAS; at = ALPHA_SRC.indexOf( pChar, mLastIndexIntoAS = 0 ); } int rv = at - mLastIndexIntoAS; mLastIndexIntoAS = at; return rv + pReturnOffset; } private static final int ASCII_CASE_DELTA = 'a' - 'A'; private int mLastIndexIntoAS = -1; // ......................................1234567-101234567-201234567-301234567-40123456 private static final String ALPHA_SRC = "quickly the brown fox jumped over a lazy goose"; private static final String OTHER_SRC = "9876543 210 /:,.; ? - + () @ $ % ' ! \""; // last from ALPHA_SRC initialized to 0. // 1-46 is the amount to add to the index of the last from ALPHA_SRC into ALPHA_SRC // 47-92 is the amount to add to the index of the last from ALPHA_SRC into ALPHA_SRC - Capitalized // 96 indicates that the next 4 characters are encrypted hex for the character. // 'a' - 'z' (97-122) are positional from the index into ALPHA_SRC in OTHER_SRC public void decode( int pChar ) { mSB.append( LLdecode( pChar ) ); } private char LLdecode( int pChar ) { if ( ('a' <= pChar) && (pChar <= 'z') ) { int at = mLastIndexIntoAS = ALPHA_SRC.indexOf( pChar ); if ( at != -1 ) { char rv = OTHER_SRC.charAt( at ); if ( rv != ' ' ) { return rv; } } } else if ( pChar == 96 ) { char[] zDigits = new char[4]; for ( int i = 0; i < zDigits.length; i++ ) { int zChar = read(); if ( zChar == -1 ) { throw new DecryptFailureException( (char) pChar, this.getClass() ); } zDigits[i] = LLdecode( zChar ); } try { return Hex.from4Chars( zDigits ); } catch ( IllegalArgumentException e ) { // fall thru } } else { boolean zCaseChange = false; if ( (47 <= pChar) && (pChar <= 92) ) { zCaseChange = true; pChar -= 46; } if ( (1 <= pChar) && (pChar <= 46) ) { if ( (mLastIndexIntoAS += pChar) >= ALPHA_SRC.length() ) { mLastIndexIntoAS -= ALPHA_SRC.length(); } char rv = ALPHA_SRC.charAt( mLastIndexIntoAS ); return !zCaseChange ? rv : (char) (rv - ASCII_CASE_DELTA); } } throw new DecryptFailureException( (char) pChar, this.getClass() ); } } // //public static void main( String argv[] ) // throws Exception //{ // BrainDeadSymmetricEncryptor zBrainDeadSymmetricEncryptor = new BrainDeadSymmetricEncryptor(); // System.out.println( HexStringCodec.toHex( // (zBrainDeadSymmetricEncryptor.getIdentifierAndVersion() + ":" + zBrainDeadSymmetricEncryptor.encrypt( argv[0] )).getBytes() ) ); //} } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/encryption/symmetric/BrainDeadSymmetricEncryptor.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
942 Diff | GeorgeS | Mon 02 Jun, 2014 23:41:46 +0000 | Extracting commonfoundation |
812 Diff | GeorgeS | Sat 18 Aug, 2012 17:45:40 +0000 | |
811 Diff | GeorgeS | Sat 18 Aug, 2012 13:45:18 +0000 | |
610 Diff | GeorgeS | Mon 12 Mar, 2012 00:54:00 +0000 | |
475 Diff | GeorgeS | Sat 03 Sep, 2011 13:54:51 +0000 | |
295 Diff | markcmarkc | Sun 26 Jun, 2011 10:17:39 +0000 | |
49 | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |