A riffle shuffle is a way of shuffling cards where the deck is split into 2 roughly equal sections and the sections are riffled into each other in small groups. This is how to riffle shuffle a string:
- Split the string into equal sections.
- Reverse the strings, and starting from the start of each string.
- Put runs of a uniformly random length between 1 and the number of characters left in the current string into the final string
- Then remove these characters from the string.
- Repeat for the other half, until both halves are empty.
An example
"Hello World!" Output string = ""
"Hello ", "World!" ""
"Hell", "World!" " o"
"Hell", "World" " o!"
"Hel", "World" " o!l"
"Hel", "Wo" " o!ldlr"
"H", "Wo" " o!ldlrle"
"H", "" " o!ldlrleoW"
"", "" " o!ldlrleoWH"
The final product from Hello World! could be o!ldlrleoWH and that is what you would output.
Cops
Your task is to make a program (or function) that will riffle shuffle a string. If the inputted string is of odd length, just split it into two uneven length strings with a relative length of +1 and +0 (abc => [ab, c] or [a, bc]). You may take input in the normal fashion and produce output in the normal fashion.
Your Cops submission will consist of 4 things
- The language you used
- The length of your program in bytes
- Your program, riffle shuffled.
- Anything else you want to add
You are aiming to keep your code from being uncracked by the Robbers for 7 days. After that period, your program is safe and you should edit in your original program. Your submission may still be cracked until you reveal your solution. The shortest, safe solution will be the winner!
-
\$\begingroup\$ Let us continue this discussion in chat. \$\endgroup\$Jonathan Allan– Jonathan Allan2018年01月01日 13:52:01 +00:00Commented Jan 1, 2018 at 13:52
-
1\$\begingroup\$ The change to uniformly random makes me a sad dragon. I had fun making an entry using a Wald Distribution (inverse gaussian). I'd love to post it. \$\endgroup\$Draco18s no longer trusts SE– Draco18s no longer trusts SE2018年01月11日 00:04:33 +00:00Commented Jan 11, 2018 at 0:04
9 Answers 9
><>, 46 bytes
}lr]l:l~\r[-r}x>o?
<!l>x![; ?=\?(0:2i
:,2-%2:
There’s almost no obfuscations in the real code, but I suspect a 2D language will be hard enough to crack anyway.
Disclaimer: Written before it was specified that it had to be uniformly random. This is not uniformly random, and I'm not sure how I'd even implement a uniformly random algorithm in><> to begin with.
Jelly, 11 bytes, Cracked
This is a golfed version so someone can probably crack it easily just by making a golfy version. There are probably a few different approaches but I suspect this approach will be decently common with golfing languages.
Ṗ/Œż€X€U2sœ
The SHA-384 hash of my intended program is 86025a659b3c5fc38e943f72b1f26e28e2e751a7118a589073f1d24fa61ff6b02753d6a0f3f0c7fee6555de69fd06a74 (using UTF-8 encoding).
-
\$\begingroup\$ Cracked \$\endgroup\$fireflame241– fireflame2412018年01月01日 03:58:11 +00:00Commented Jan 1, 2018 at 3:58
-
\$\begingroup\$ @fireflame241 good job +1 \$\endgroup\$2018年01月01日 17:32:57 +00:00Commented Jan 1, 2018 at 17:32
Python 3, 154 bytes (list of chars -> list of chars) (function) Cracked
[=o;]1-::[]:s[i,]1-::[]s:[i=R,L;2//)i(nel=s
:)i(r fed
*tropmi modR+L+o nruter
]:s[L,R=R,L;]s:[L=+o;))L(nel,1(tnidnar=s:R dna L elihw
]nar morf
I doubt this will be too hard to crack, especially since riffling once is rather ineffective (you can see entire program components in the output...). This is mostly just to get things rolling. There might be some whitespace (including newlines) that I didn't copy correctly. The SHA-384 hash of my intended solution is
5924530418bf8cd603c25da04ea308b124fdddfc61e7060d78b35e50ead69a7fbde9200b5ee16635cc0ee9df9c954fa1.
-
\$\begingroup\$ @H.PWiz Python. Whoops, forgot to add it in (also bytecount, thanks for the reminder!) \$\endgroup\$2018年01月01日 03:21:56 +00:00Commented Jan 1, 2018 at 3:21
-
\$\begingroup\$ In theory, could you just try reverse riffle shuffling the code and executing it with python until it works? \$\endgroup\$fəˈnɛtɪk– fəˈnɛtɪk2018年01月01日 03:27:56 +00:00Commented Jan 1, 2018 at 3:27
-
\$\begingroup\$ @fəˈnɛtɪk Theoretically that should work... It may take you a while though :P \$\endgroup\$2018年01月01日 03:28:17 +00:00Commented Jan 1, 2018 at 3:28
-
1\$\begingroup\$ @fəˈnɛtɪk That's just like try solving the programming language quiz with TIO brute force. There is no fun in doing it. \$\endgroup\$user202729– user2027292018年01月01日 03:31:52 +00:00Commented Jan 1, 2018 at 3:31
-
1\$\begingroup\$ Recracked \$\endgroup\$fireflame241– fireflame2412018年01月01日 19:49:00 +00:00Commented Jan 1, 2018 at 19:49
Röda, 118 bytes
2//x#=z}][=]:y[x
}]0>)b..a(#[]1-::[]:y[x
x#%)(reelihw}]0>b#[fi)b(g
getnI]0>a#[fi)a(g{]mo:z[x=b]zdnar=y|x|{=:[g{xx=a
f
It takes a stream of characters as input and outputs a stream of characters.
R, 283 bytes, Cracked
/n,s(daeh-<l
))'',s(tilpsrts(le::sdohtem-<s
)s(rahcn-<n{)s(noitcnufhtgnel(fi
})x-,l(liat-<l
)))x,l(daeh(ver,o(c-<o
)1,)l(htgnel(elihw
}{-<o
)2/n,s(liat-<r
)2'=pes,o(tac
}})y-,r(liat-<r
)))y,r(daeh(ver,o(c-<o
)1,)r(htgnel(elpmas-<y{))r(l(fi{))r(htgnel|)l(htgnel()'htgne}(lpmas-<x{))le
I realize now that writing a longer answer has more "runs" of characters that are preserved, alas.
Good luck!
-
-
\$\begingroup\$ @Mr.Xcoder thanks for the edit \$\endgroup\$Giuseppe– Giuseppe2018年01月03日 17:16:07 +00:00Commented Jan 3, 2018 at 17:16
APL (Dyalog Unicode), 62 bytes
(g÷f ̈()⍵(≢~⊃⍵⍺⍉⍨⍨}(←(←'')⊂f≢(g∘⌈ ̈}{?↑-⍵↑⋄)≢)))≢⊂{,⋄⍵⍵↑2f≢∘⊃?()
SHA-384 of my intended solution: 3209dba6ce8abd880eb0595cc0a334be7e686ca0aa441309b7c5c8d3118d877de2a48cbc6af9ef0299477e3170d1b94a
This is probably easy enough, especially since most of the people in the APL chat helped me build this answer.
Pyth, 14 bytes, Cracked
_Qm/dc2iF.jk.O
Pretty standard-issue Pyth implementation to test the waters. May be quite easy to crack, but I guess we'll see how it fares.
-
\$\begingroup\$ Cracked! \$\endgroup\$Mr. Xcoder– Mr. Xcoder2018年01月01日 08:25:03 +00:00Commented Jan 1, 2018 at 8:25
Random Brainfuck, 273 bytes
]<.[<<]<[<<]<[<]<,.[<]-<<<]>>>>>]<+>-[<]<+>-[<<]>]>+<]<]>[>>]]>[>>]<]<+>-[[<<]>]>[>>]<-[[[>>]]>[>]<+>-[[<]<[[?>>]<+>-[[<]-<]>]<[>>]<<+>>+>-[[<<,[>]<.[<]>[>]<+>-[<]>[>]->>>]<<<<<]>+-[<<-[>]>+<-[>>]<]<+>-[[[<<]]<[<]>+<-[[><]<[[>]<+>-[>],]<+>-[<]<->>+]>[[<-[<?<<+>>>[,]>+<-[[>
Random brainfuck is the same as normal brainfuck, but it introduces the ? character, which sets the current cell to a random value. Fun note; I had a version of this that only worked for inputs of less than 256 characters, for obvious reasons, but the code itself was longer than that. When I changed it to handle longer, it turned out to be one byte shorter than the original. ̄\_(ツ)_/ ̄.
Pushy, 25 bytes, Cracked
iUL1[N@O;?x?v:/2L=0LF;.':
Takes input as a "quoted string" on the command line.
-
-
\$\begingroup\$ Should the
1Lbe the other way around? Otherwise you're adding 1 to the length \$\endgroup\$Jo King– Jo King2018年01月09日 00:35:59 +00:00Commented Jan 9, 2018 at 0:35 -
\$\begingroup\$ @JoKing Correct, and nice crack! \$\endgroup\$FlipTack– FlipTack2018年01月09日 23:17:36 +00:00Commented Jan 9, 2018 at 23:17
Explore related questions
See similar questions with these tags.