Riffle shuffle a string - Cops

8

1

Robbers post

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!

caird coinheringaahing

Posted 2018-01-01T02:45:53.440

Reputation: 13 702

Let us continue this discussion in chat.

– Jonathan Allan – 2018-01-01T13:52:01.770

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. – Draco18s no longer trusts SE – 2018-01-11T00:04:33.103

Answers

2

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).

HyperNeutrino

Posted 2018-01-01T02:45:53.440

Reputation: 26 575

Cracked – fireflame241 – 2018-01-01T03:58:11.793

@fireflame241 good job +1 – HyperNeutrino – 2018-01-01T17:32:57.117

2

><>, 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.

Jo King

Posted 2018-01-01T02:45:53.440

Reputation: 38 234

1

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.

HyperNeutrino

Posted 2018-01-01T02:45:53.440

Reputation: 26 575

@H.PWiz Python. Whoops, forgot to add it in (also bytecount, thanks for the reminder!) – HyperNeutrino – 2018-01-01T03:21:56.233

In theory, could you just try reverse riffle shuffling the code and executing it with python until it works? – fəˈnɛtɪk – 2018-01-01T03:27:56.587

@fəˈnɛtɪk Theoretically that should work... It may take you a while though :P – HyperNeutrino – 2018-01-01T03:28:17.940

@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. – user202729 – 2018-01-01T03:31:52.183

Cracked – fireflame241 – 2018-01-01T03:48:51.383

randint includes both endpoints, so you'd need len(i)-1. This might have invalidated your riffled code too. (e.g. running with an input ABCD, assuming left always goes first shouldn't be able to result in CDBA, but this does - assuming the crack is right of course!) – Jonathan Allan – 2018-01-01T12:08:59.893

Furthermore all the runs should be in reverse order (like the dlr selection in the example). – Jonathan Allan – 2018-01-01T12:13:04.997

@JonathanAllan Theoretically the randint thing shouldn't cause any issues because if s == len(L) then nothing will happen in the remainder of the loop. I fixed the reverse run thing though, I'll add a comment on the cracked post. – HyperNeutrino – 2018-01-01T17:30:58.627

Something does happen - R&L swap over, so you get to choose 0 then swap sides. – Jonathan Allan – 2018-01-01T17:32:53.113

@JonathanAllan oh good point. Hmm I'll have to fix that somehow then. – HyperNeutrino – 2018-01-01T18:18:35.920

...I see you fixed it (my fix was 152 ;p) – Jonathan Allan – 2018-01-01T18:25:04.880

1Recracked – fireflame241 – 2018-01-01T19:49:00.037

1

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!

Giuseppe

Posted 2018-01-01T02:45:53.440

Reputation: 21 077

Cracked – fergusq – 2018-01-02T09:38:16.393

@Mr.Xcoder thanks for the edit – Giuseppe – 2018-01-03T17:16:07.757

1

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.

fergusq

Posted 2018-01-01T02:45:53.440

Reputation: 4 867

0

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.

notjagan

Posted 2018-01-01T02:45:53.440

Reputation: 4 011

Cracked! – Mr. Xcoder – 2018-01-01T08:25:03.550

0

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. ¯\_(ツ)_/¯.

Jo King

Posted 2018-01-01T02:45:53.440

Reputation: 38 234

0

Pushy, 25 bytes, Cracked

iUL1[N@O;?x?v:/2L=0LF;.':

Takes input as a "quoted string" on the command line.

FlipTack

Posted 2018-01-01T02:45:53.440

Reputation: 13 242

Cracked – Jo King – 2018-01-09T00:26:46.467

Should the 1L be the other way around? Otherwise you're adding 1 to the length – Jo King – 2018-01-09T00:35:59.403

@JoKing Correct, and nice crack! – FlipTack – 2018-01-09T23:17:36.080

0

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.

J. Sallé

Posted 2018-01-01T02:45:53.440

Reputation: 3 233