![]() |
|
[challenge] tiny scrambler - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: [challenge] tiny scrambler (/Thread-challenge-tiny-scrambler) |
[challenge] tiny scrambler - Inori - 06-01-2015 Wow, a challenge that doesn't involve generating stuff! The purpose of this one is to take user input and scramble it. The difference between this and my other challenges is you'll need to provide 2 programs: one for scrambling it, and one for deciphering the scrambled text. Providing sample input/outputs is appreciated, too. Rules: -No imports (of any kind, including bash) -No more than one loop per program -10 NSP prize for lowest score (negatives possible) Score calculation: average lines(add both programs and divide by 2) - complexity(chosen by me, 1 is crap; 10 is ridiculous) Spoiler: My solution (Ruby):
Score: 1 (3 line average - 2 complexity) Scramble: Code: chars = [("a".."z").to_a, ("0".."9").to_a, "a", "b"].flatten
message = gets.chomp.downcase.split("")
message.each { |l| l = chars[chars.index(l) + 2] if chars.include?(l); print l }Decipher: Code: chars = [("a".."z").to_a, ("0".."9").to_a, "a", "b"].flatten
message = gets.chomp.downcase.split("")
message.each { |l| l = chars[chars.index(l) - 2] if chars.include?(l); print l }I/O: Code: test 123
=> rcqr z01Scores: @"Chitoge": 1 @Eclipse: -1.5 RE: [challenge] tiny scrambler - lux - 06-01-2015 Mind defining scrambled? Will attempt this when I get home with JS. RE: [challenge] tiny scrambler - Inori - 06-01-2015 (06-01-2015, 01:36 PM)Lux Wrote: Mind defining scrambled? By scrambled, I mean anything from shifting alphabetical values to incorporating professional encryption algorithms. RE: [challenge] tiny scrambler - Eclipse - 06-01-2015 Spoiler: scramble.pyCode: new = ''
for x in raw_input('> ')[::-1]:
new += str(hex(ord(x) + 1))
print (new[::-1]).replace('x0', '')What the above program does is reverses the string, and then for each character in the string, it changes it to a decimal representation, adds one to the resulting integer (This integer can be changed and used as a very basic password encoding system), and then converts it into HEX. It then removes the HEX identifiers so it's just a fucking baffling string. Example: Code: > OMG, I am gay and love cock.
05e484d212a41226e6128626a71226f65612d607776612460746c6f2Lines: 4 Spoiler: unscramble.pyCode: old = raw_input('> ').strip()[::-1]
new = ''
for x in [old[i:i+2] for i in range(0, len(old), 2)]:
new += chr(int('0x' + x, 16) - 1)
print new[::-1]The above program reverses the aforementioned process. Again, the integer can be used a very basic passcode system. Example: Code: > 05e484d212a41226e6128626a71226f65612d607776612460746c6f2
OMG, I am gay and love cock.Lines: 5 Average line count: 4.5 EDIT: I forgot to mention one thing. As it's using a basic passcode system AND the HEX identifiers have been removed, a standard decode method wouldn't work. If the user is super advanced, and they suspect that it's HEX, they could perform a decode: ('0x' isn't needed for conversion to decimal.) Example: Code: >05e484d212a41226e6128626a71226f65612d607776612460746c6f2
ä„Ò¤&æ†&§&öVÖwfFFÆò
^^This is meant to say: 'OMG, I am gay and love cock.'As you can see, that failed spectacularly. Done @"Chitoge". Edit2: Fixed bug. RE: [challenge] tiny scrambler - Eclipse - 06-27-2015 So, ermm. Did I win? It's been a while. RE: [challenge] tiny scrambler - Lysergide - 06-27-2015 I just tried to build something in the last hour, but i can't beat the simplicity and effectiveness of eclipse's programs. I might give a try tomorrow or in the next few days, but I think I am out of time for this challenge
RE: [challenge] tiny scrambler - Shebang - 07-08-2015 Encode: Code: print'#'.join(oct(ord(x)^17)[::-1]for x in raw_input())Decode: Code: print''.join(chr(int(x[::-1],8)^17)for x in raw_input().split("#"))Not very complex, but my score is guaranteed to be <= 1. RE: [challenge] tiny scrambler - Akane - 07-08-2015 (07-08-2015, 01:23 AM)Shebang Wrote: Encode: One liners? Damn.
RE: [challenge] tiny scrambler - 0xDEAD10CC - 07-10-2015 Scrambling effectively means keeping the same data, but with a different order. You clearly fail with the definition of the word because it means nothing close to encryption... RE: [challenge] tiny scrambler - 0xDEAD10CC - 07-11-2015 Here's my solution anyways, even though it's not necessarily "tiny": Code: #include <stdio.h>
void toggle_encrypt(const unsigned char *src, size_t src_len, unsigned char *dst)
{
size_t n = 0;
while (n < src_len)
{
dst[n] = ((src[n] << 4) & 0xF0) | (src[n] >> 4);
++n;
}
}
int main()
{
size_t i;
char input[] = "Testing by 0xDEAD10CC.";
unsigned char encrypted[sizeof(input)];
char decrypted[sizeof(input)];
printf(" Original: %s\n", input);
fputs("Encrypted: ", stdout);
toggle_encrypt((unsigned char *)input, sizeof(input), encrypted);
for (i = 0; i < sizeof(encrypted); ++i)
printf("%.2X ", encrypted[i]);
fputc('\n', stdout);
fputs("Decrypted: ", stdout);
toggle_encrypt(encrypted, sizeof(encrypted), (unsigned char *)decrypted);
decrypted[sizeof(decrypted) - 1] = 0;
puts(decrypted);
return 0;
}Result: Code: Original: Testing by 0xDEAD10CC.
Encrypted: 45 56 37 47 96 E6 76 02 26 97 02 03 87 44 54 14 44 13 03 34 34 E2 00
Decrypted: Testing by 0xDEAD10CC. |