Last active
August 29, 2015 13:57
-
-
Save nornagon/9635846 to your computer and use it in GitHub Desktop.
Corrupt random bits in a string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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