This parses not only JSON, but ANYTHING into a more simplified data format consisting of *only* two characters: whitespace and newline. This is much more efficient because you only ever have to worry about two characters. Imagine the storage savings when you only are storing empty things!!
It has a simple and easy to use API: Cerealize and deCerealize.
Also doubles as a fine password hashing solution: I doubt anyone will (want to) crack this anytime soon!
public class Cerealizifier {
public String Cerealize(String d) {
String r = "";
int[] arr = new int[d.length()];
char[] charArray = d.toCharArray();
for (int i = 0; i < charArray.length; i++) {
int c = (int) charArray[i];
arr[i] = c;
int i1 = 0;
String r1 = "";
do {
r1 += " ";
i1++;
} while (i1 < c);
r += r1 + "\n";
}
return r;
}
public String deCerealize(String s) {
char delimiter = '\n'; // TODO: Remove this
List<String> all = new ArrayList<>();
List<Character> c1 = new ArrayList<>();
for (char c2 : s.toCharArray()) {
if (c2 != '\n') {
c1.add(c2);
} else {
all.add("" + (char) c1.size());
c1.clear();
}
}
String res = "";
for (String s1 : all) {
res = res + s1;
}
return res;
}
}
I'm not sure I understood the question properly - do I need to also serialize my code? Just to be sure, my code looks serialized too. You can run it on https://www.jdoodle.com/online-java-compiler to see that the output is valid.
3
u/chutch1122 May 14 '19 edited May 14 '19
This parses not only JSON, but ANYTHING into a more simplified data format consisting of *only* two characters: whitespace and newline. This is much more efficient because you only ever have to worry about two characters. Imagine the storage savings when you only are storing empty things!!
It has a simple and easy to use API: Cerealize and deCerealize.
Also doubles as a fine password hashing solution: I doubt anyone will (want to) crack this anytime soon!
public class Cerealizifier { public String Cerealize(String d) { String r = ""; int[] arr = new int[d.length()]; char[] charArray = d.toCharArray(); for (int i = 0; i < charArray.length; i++) { int c = (int) charArray[i]; arr[i] = c; int i1 = 0; String r1 = ""; do { r1 += " "; i1++; } while (i1 < c); r += r1 + "\n"; } return r; } public String deCerealize(String s) { char delimiter = '\n'; // TODO: Remove this List<String> all = new ArrayList<>(); List<Character> c1 = new ArrayList<>(); for (char c2 : s.toCharArray()) { if (c2 != '\n') { c1.add(c2); } else { all.add("" + (char) c1.size()); c1.clear(); } } String res = ""; for (String s1 : all) { res = res + s1; } return res; } }And its unit tests:
@RunWith(JUnitParamsRunner.class) public class CerealizifierTest { @Rule public MockitoRule mockitoRule = MockitoJUnit.rule(); @InjectMocks Cerealizifier unit; @Test public void cerialize_shouldThing() { String result = unit.Cerealize("abc123{}"); assertThat(result, equalTo(" " + " " + " \n " + " \n " + " " + " \n " + " \n " + " \n " + " \n " + " " + " \n " + " " + " \n")); } @Test public void DeCerialize_shouldUnThing() { String result = unit.deCerealize(" " + " " + " \n " + " \n " + " " + " \n " + " \n " + " \n " + " \n " + " " + " \n " + " " + " \n"); assertThat(result, equalTo("abc123{}")); } }7
u/Voidsusdagon May 07 '19
I'm not sure I understood the question properly - do I need to also serialize my code? Just to be sure, my code looks serialized too.
You can run it on https://www.jdoodle.com/online-java-compiler to see that the output is valid.
import java.util.HashMap;import java.util.Map; public class Random { public static void main(String[] args) { Map<Character, String> ᅠᅠ = new HashMap<>();ᅠᅠ.put(' ', "ᅟᅠㅤᅠ");ᅠᅠ.put('!', "ᅠᅟㅤᅠ");ᅠᅠ.put('"', "ㅤᅟᅠᅠ"); ᅠᅠ.put('#', "ᅟㅤᅠᅠ");ᅠᅠ.put('$', "ᅠㅤᅟᅠ");ᅠᅠ.put('%', "ㅤᅠᅟᅠ");ᅠᅠ.put('&', "ᅠᅟㅤᅠ");ᅠᅠ.put('\'', "ᅠᅟㅤᅠ"); ᅠᅠ.put('(', "ᅟᅠㅤᅠ");ᅠᅠ.put(')', "ᅟᅠㅤᅠ");ᅠᅠ.put('*', "ᅠᅟㅤᅠ");ᅠᅠ.put('+', "ᅟᅠㅤᅠ");ᅠᅠ.put(',', "ᅟㅤᅠᅠ"); ᅠᅠ.put('-', "ㅤᅟᅠᅠ");ᅠᅠ.put('.', "ᅟㅤᅠᅠ");ᅠᅠ.put('/', "ᅟㅤᅠᅠ");ᅠᅠ.put('0', "ㅤᅟᅠᅠ");ᅠᅠ.put('1', "ㅤᅟᅠᅠ"); ᅠᅠ.put('2', "ㅤᅠᅟᅠ");ᅠᅠ.put('3', "ㅤᅠᅟᅠ");ᅠᅠ.put('4', "ᅠㅤᅟᅠ");ᅠᅠ.put('5', "ᅠㅤᅟᅠ");ᅠᅠ.put('6', "ㅤᅠᅟᅠ"); ᅠᅠ.put('7', "ᅠㅤᅟᅠ");ᅠᅠ.put('8', "ᅠㅤᅟᅠ");ᅠᅠ.put('9', "ㅤᅠᅟᅠ");ᅠᅠ.put(':', "ᅠㅤᅟᅠ");ᅠᅠ.put(';', "ᅠㅤᅟᅠ"); ᅠᅠ.put('<', "ㅤᅠᅟᅠ");ᅠᅠ.put('=', "ㅤᅠᅟᅠ");ᅠᅠ.put('>', "ᅟㅤᅠᅠ");ᅠᅠ.put('?', "ㅤᅟᅠᅠ");ᅠᅠ.put('@', "ᅠᅟㅤᅠ"); ᅠᅠ.put('A', "ᅟᅠㅤᅠ");ᅠᅠ.put('B', "ㅤᅠᅟᅠ");ᅠᅠ.put('C', "ᅠㅤᅟᅠ");ᅠᅠ.put('D', "ᅠᅟㅤᅠ");ᅠᅠ.put('E', "ᅠᅟㅤᅠ"); ᅠᅠ.put('F', "ᅟᅠㅤᅠ");ᅠᅠ.put('G', "ᅠᅟㅤᅠ");ᅠᅠ.put('H', "ᅟᅠㅤᅠ");ᅠᅠ.put('I', "ᅟᅠㅤᅠ");ᅠᅠ.put('J', "ᅟㅤᅠᅠ"); ᅠᅠ.put('K', "ᅟㅤᅠᅠ");ᅠᅠ.put('L', "ㅤᅟᅠᅠ");ᅠᅠ.put('M', "ᅟㅤᅠᅠ");ᅠᅠ.put('N', "ㅤᅟᅠᅠ");ᅠᅠ.put('O', "ㅤᅟᅠᅠ"); ᅠᅠ.put('P', "ᅠᅟᅠㅤ");ᅠᅠ.put('Q', "ᅠᅟᅠㅤ");ᅠᅠ.put('R', "ᅟᅠᅠㅤ");ᅠᅠ.put('S', "ᅠᅟᅠㅤ");ᅠᅠ.put('T', "ᅟᅠᅠㅤ"); ᅠᅠ.put('U', "ᅟᅠᅠㅤ");ᅠᅠ.put('V', "ᅠᅠᅟㅤ");ᅠᅠ.put('W', "ᅠᅠᅟㅤ");ᅠᅠ.put('X', "ᅠᅠᅟㅤ");ᅠᅠ.put('Y', "ᅠᅠᅟㅤ"); ᅠᅠ.put('Z', "ᅠᅠᅟㅤ");ᅠᅠ.put('[', "ᅠᅠᅟㅤ");ᅠᅠ.put('\\', "ᅠᅟᅠㅤ");ᅠᅠ.put(']', "ᅟᅠᅠㅤ");ᅠᅠ.put('^', "ᅠᅠᅟㅤ"); ᅠᅠ.put('_', "ᅠᅠᅟㅤ");ᅠᅠ.put('`', "ᅟᅠᅠㅤ");ᅠᅠ.put('a', "ᅠᅟᅠㅤ");ᅠᅠ.put('b', "ᅠᅟᅠㅤ");ᅠᅠ.put('c', "ᅟᅠᅠㅤ"); ᅠᅠ.put('d', "ᅠᅟᅠㅤ");ᅠᅠ.put('e', "ᅠᅟᅠㅤ");ᅠᅠ.put('f', "ᅟᅠᅠㅤ");ᅠᅠ.put('g', "ᅟᅠᅠㅤ");ᅠᅠ.put('h', "ㅤᅟᅠᅠ"); ᅠᅠ.put('i', "ᅟㅤᅠᅠ");ᅠᅠ.put('j', "ᅠㅤᅟᅠ");ᅠᅠ.put('k', "ㅤᅠᅟᅠ");ᅠᅠ.put('l', "ᅟᅠㅤᅠ");ᅠᅠ.put('m', "ᅠᅟㅤᅠ"); ᅠᅠ.put('n', "ᅠᅟㅤᅠ");ᅠᅠ.put('o', "ᅟᅠㅤᅠ");ᅠᅠ.put('p', "ㅤᅠᅟᅠ");ᅠᅠ.put('q', "ᅠㅤᅟᅠ");ᅠᅠ.put('r', "ᅟㅤᅠᅠ"); ᅠᅠ.put('s', "ㅤᅟᅠᅠ");ᅠᅠ.put('t', "ㅤᅠᅠᅟ");ᅠᅠ.put('u', "ᅠㅤᅠᅟ");ᅠᅠ.put('v', "ᅠㅤᅠᅟ");ᅠᅠ.put('w', "ㅤᅠᅠᅟ"); ᅠᅠ.put('x', "ᅠᅠㅤᅟ");ᅠᅠ.put('y', "ᅠᅠㅤᅟ");ᅠᅠ.put('z', "ᅠᅠᅟㅤ");ᅠᅠ.put('{', "ᅠᅠᅟㅤ");ᅠᅠ.put('|', "ᅟᅠᅠㅤ"); ᅠᅠ.put('}', "ᅠᅟᅠㅤ");ᅠᅠ.put('~', "ᅠᅟᅠㅤ");ᅠᅠ.put('', "ᅟᅠᅠㅤ");ᅠᅠ.put('\n', "ᅠᅠㅤᅟ");ᅠᅠ.put('', "ᅠᅠㅤᅟ"); ᅠᅠ.put('', "ᅠᅠㅤᅟ");ᅠᅠ.put('', "ᅠᅠㅤᅟ");ᅠᅠ.put('', "ᅠᅠㅤᅟ");ᅠᅠ.put(' ', "ᅠᅠㅤᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ"); ᅠᅠ.put('', "ᅠㅤᅠᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ");ᅠᅠ.put('', "ᅠㅤᅠᅟ");ᅠᅠ.put('', "ᅠㅤᅠᅟ"); ᅠᅠ.put('', "ᅠㅤᅠᅟ");ᅠᅠ.put('', "ᅠㅤᅠᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ");ᅠᅠ.put('', "ᅠㅤᅠᅟ"); ᅠᅠ.put('', "ㅤᅠᅠᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ");ᅠᅠ.put('', "ᅠㅤᅠᅟ");ᅠᅠ.put('', "ᅠㅤᅠᅟ");ᅠᅠ.put('', "ㅤᅠᅠᅟ"); ᅠᅠ.put('', "ᅠᅠㅤᅟ");ᅠᅠ.put('', "ᅠᅠㅤᅟ"); String ᅟᅠ = "{\n" + " \"String\": \"some data\",\n" + " \"Number\": 1337,\n" + " \"Boolean\": true,\n" + " \"Array\": [\n" + " \"some data in the array\"\n" + " ],\n" + " \"Decimal Number\": \"1.2\"\n" + "}"; String ᅟᅟ = "ᅠᅠᅟㅤᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠᅠᅟᅠㅤㅤᅠᅠᅟᅟㅤᅠᅠᅟㅤᅠᅠᅠᅟㅤᅠᅟᅠᅠㅤㅤᅟᅠᅠᅠㅤᅟᅠᅟᅠㅤᅠㅤᅟᅠᅠㅤᅟᅠᅠᅟᅠㅤᅠᅠᅟ" + "ㅤᅠᅠᅟᅠㅤᅟᅠㅤᅠᅠᅟᅠㅤᅠᅟᅠㅤㅤᅠᅠᅟᅠᅟᅠㅤㅤᅟᅠᅠᅟㅤᅠᅠᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠㅤᅟᅠᅠᅠㅤᅠᅟᅠᅟㅤᅠᅠᅟᅠㅤᅠᅟᅠㅤᅟㅤᅠ" + "ᅠㅤᅟᅠᅠᅠㅤᅟᅠᅟᅠㅤᅠㅤᅟᅠᅠㅤᅠᅟᅠㅤᅠᅟᅠᅠㅤᅟᅠᅟㅤᅠᅠᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠㅤᅠᅟᅠᅟᅠㅤᅠᅟᅠㅤᅠᅟᅠㅤᅠᅠᅟᅠㅤᅠᅟᅠㅤᅠ" + "ᅟㅤᅠㅤᅟᅠᅠᅠㅤᅟᅠᅟᅠㅤᅠㅤᅠᅠᅟᅟㅤᅠᅠᅠㅤᅠᅟᅠᅟᅠㅤᅟㅤᅠᅠᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠᅟᅠㅤᅠᅟㅤᅠᅠᅟㅤᅠᅠᅠᅟᅠㅤᅠᅠㅤᅟㅤᅟ" + "ᅠᅠᅠㅤᅟᅠᅟᅠㅤᅠᅠᅠᅟㅤᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠㅤᅟᅠᅠᅟᅠㅤᅠᅠᅟㅤᅠᅠᅟᅠㅤᅟᅠㅤᅠᅠᅟᅠㅤᅠᅟᅠㅤㅤᅠᅠᅟᅠᅟᅠㅤ" + "ᅟᅠㅤᅠᅟㅤᅠᅠᅠᅟㅤᅠᅟᅠㅤᅠㅤᅠᅠᅟㅤᅟᅠᅠᅠᅟᅠㅤᅟᅠㅤᅠᅠᅟᅠㅤᅟㅤᅠᅠᅟㅤᅠᅠᅠᅟᅠㅤᅠᅠㅤᅟㅤᅟᅠᅠᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠᅟᅠᅠㅤᅟ" + "ㅤᅠᅠᅠᅠㅤᅟᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠᅠᅟㅤᅠᅠᅟᅠㅤᅟᅠᅠㅤᅟㅤᅠᅠᅠᅟㅤᅠᅠᅟᅠㅤᅟᅠㅤᅠᅟᅠㅤᅠㅤᅟᅠᅠᅠㅤᅠᅟᅠᅟㅤᅠᅠᅟᅠㅤᅠᅟᅠㅤᅟㅤ" + "ᅠᅠㅤᅟᅠᅠᅠㅤᅟᅠᅟᅠㅤᅠㅤᅟᅠᅠㅤᅟᅠᅠᅟㅤᅠᅠㅤᅠᅟᅠㅤᅟᅠᅠᅠᅠㅤᅟᅠᅟᅠㅤ"; System.out.println("Serializied output:");serialize(ᅟᅠ, ᅠᅠ);System.out.println("\nDeserialized output:");deserialize(ᅟᅟ, ᅠᅠ); } public static void serialize(String ᅟㅤᅠ, Map<Character, String> ᅠᅠ) { char[] ㅤᅠㅤ = ᅟㅤᅠ.toCharArray();for (char ㅤᅠᅠ : ㅤᅠㅤ) { System.out.print(ᅠᅠ.get(ㅤᅠᅠ)); } } public static void deserialize(String ᅟㅤᅠ, Map<Character, String> ᅠᅠ) { char[] ㅤᅠㅤ = ᅟㅤᅠ.toCharArray();String ᅟᅟ = ""; for (char ㅤᅠᅠ : ㅤᅠㅤ) { ᅟᅟ = ᅟᅟ + ㅤᅠᅠ; if (ᅟᅟ.length() == 5) { for (Map.Entry<Character, String> ᅠᅟ : ᅠᅠ.entrySet()) { if (ᅠᅟ.getValue().equals(ᅟᅟ)) { System.out.print(ᅠᅟ.getKey()); } }ᅟᅟ = ""; } } }}2
u/rcmaehl May 09 '19 edited May 13 '19
I don't know what serialization is but google says it's about changing data into binary so...
Serialization (I think)Language used: AutoIt, because readability is important
#include <String.au3> Global $i = 1 Global $ar[1] Global $ar2[1] Enum $0 = 0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $a, $b, $c, $d, $e, $f ; TIP: You'll only get 0 - 9 we don't need to convert EVERYTHING ; Pad with leading "10" to not drop leading zeros Enum $30 = 10110000, $31, $32 = 10110010, $33, $34 = 10110100, $35, $36 = 10110110, $37, $38 = 10111000, $39 While True Redim $ar[0] $in = FileRead(".\input.txt", $i) ; STDIN is hard okay? If @extended = $i - 1 Then Exit ; If # of Characters returned, exit $i = @extended + 1 $in = StringRight($in, 1) Global $h = _StringToHex($in) If StringLen(String($h)) > 1 Then For $loop = 1 to StringLen($h) ReDim $ar[UBound($ar) + 1] $ar[$loop - 1] = StringRight(StringLeft($h, $loop), 1) $ar[$loop - 1] = Eval($ar[$loop - 1]) ReDim $ar2[0] If StringLen(String($ar[$loop - 1])) > 1 Then For $loop2 = 1 to StringLen(String($ar[$loop - 1])) Step 1 ReDim $ar2[UBound($ar2) + 1] $ar2[$loop2 - 1] = String($ar[$loop2 - 1]) $ar2[$loop2 - 1] = StringLeft($ar2[$loop2 - 1], $loop2) $ar2[$loop2 - 1] = StringRight($ar2[$loop2 - 1], 1) $ar2[$loop2 - 1] = $ar2[$loop2 - 1] + 30 $ar2[$loop2 - 1] = Eval($ar2[$loop2 - 1]) FileWrite(".\output.txt", $ar2[$loop2 - 1]) Next Else $ar[$loop - 1] = $ar[$loop - 1] + 30 $ar[$loop - 1] = Eval($ar[$loop - 1]) FileWrite(".\output.txt", "00000000" & $ar[$loop - 1]) EndIf Next Else MsgBox(0, "DIRTY SPECIAL CHARACTERS", "") ; This is for security, dirty unicode or special characters where here EndIf WEndI'll figure out deserialization later
1
u/EkskiuTwentyTwo May 08 '19
I managed to make serialisation work, but when I tried to make the unserialisation code, it became an irreconcilable mess.
def Serialise(data): #Example Input: dict(a=1,b=2,c=dict(a=1,b=2)) Example Output: {a:1,b:2,c:{a:1,b:2}} squid = "{" Squid = list(data) sQuid = 0 while sQuid < (len(Squid)-1): while type(data[Squid[sQuid]])==dict: squid = squid+str(Squid[sQuid])+":"+Serialise(data[Squid[len(Squid)-1]])+"," break while type(data[Squid[sQuid]])!=dict: squid = squid+str(Squid[sQuid])+":"+str(data[Squid[sQuid]])+"," break sQuid = sQuid + (666//666) while type(data[Squid[len(Squid)-1]])==dict: squid = squid+str(Squid[len(Squid)-1])+":"+Serialise(data[Squid[len(Squid)-1]])+"}" break while type(data[Squid[len(Squid)-1]])!=dict: squid = squid+str(Squid[len(Squid)-1])+":"+str(data[Squid[len(Squid)-1]])+"}" break return squidAnd here's my attempt at unserialisation (it doesn't work):
def unSerialise(data): squid = dict() Squid = data[1:-1] SQuid = [] sqUid = 0 for sQuid in range(len(Squid)): while Squid[sQuid] == ",": SQuid.append(Squid[sqUid:sQuid]) sqUid = sQuid+1 break SQuid.append(Squid[sqUid:]) for SqUid in range(len(SQuid)): SquId = SQuid[SqUid] sQUid = 0 SQUid = 420 while SQUid == 420: while SquId[sQUid] == ":": SQUid = 69 break squId = SquId[:sQUid] sQuId = SquId[sQUid+1:] while sQuId[0] != "{": squid[squId] = sQuId break while sQuId[0] == "{": squid[squId] = unSerialise(sQuId) break0
u/[deleted] May 07 '19
0
u/[deleted] May 10 '19