I am working on an encrypt / decrypt function. The encrypt part of it removes all spaces between characters (if there is any) then 'packs' the string into a condensed form. It then takes every other character and puts each alternating character in alternating strings. IE string "ABCD" ~> String1 = "AC" String2= "BD". it then adds them together to form String_encrypted = "ACBD".
My question is, I have to find exactly half the length and split the two strings into seperate strings again to decrypt. This works great if the string is even, however when the string is odd it rounds down because i have an int. I have been unsuccessful in using the floor or ceiling funtion in java, If someone could PLEASE just show me what I am doing wrong here is what I have...
public String railFenceDecode( String rail_fence_encoded ){
String s1 = "";
String s2 = "";
String rail_fence_packed_encoded = railFenceEncode(rail_fence_encoded);
double length.ceil((rail_fence_packed_encoded.length() / 2) + .4 );
String rail_fence_decoded = rail_fence_packed_encoded.substring(length);
// String rail_fence_decoded = rail_fence_packed_encoded;
return rail_fence_decoded;
}
My question is, I have to find exactly half the length and split the two strings into seperate strings again to decrypt. This works great if the string is even, however when the string is odd it rounds down because i have an int. I have been unsuccessful in using the floor or ceiling funtion in java, If someone could PLEASE just show me what I am doing wrong here is what I have...
public String railFenceDecode( String rail_fence_encoded ){
String s1 = "";
String s2 = "";
String rail_fence_packed_encoded = railFenceEncode(rail_fence_encoded);
double length.ceil((rail_fence_packed_encoded.length() / 2) + .4 );
String rail_fence_decoded = rail_fence_packed_encoded.substring(length);
// String rail_fence_decoded = rail_fence_packed_encoded;
return rail_fence_decoded;
}