Skip to content

Instantly share code, notes, and snippets.

@nornagon
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nornagon/9635846 to your computer and use it in GitHub Desktop.
Save nornagon/9635846 to your computer and use it in GitHub Desktop.
Corrupt random bits in a string
str = "Zalgo, he comes! He rises from the deep, he consumes us"
str.split(//).map { |char|
char.ord.to_s(2).split(//).map { |bit|
if rand < 0.01 then ["0","1"][(rand*2).floor] else bit end
}.join.to_i(2).chr
}.join
# => "Zalgo, he comes! He rises bRom the deep, `e conwumes us"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment