1 -- kubgen in haskell
  2 -- change plainText to the text you want to hash
  3 -- to dispaly the kubgen numbers:
  4 -- mapM_ putStrLn (krows churnHash)
  5 -- to dispaly the kubgen  picture:
  6 -- mapM_ putStrLn (krows kpicture)
  7 
  8 
  9 hsh :: String
 10 hsh= concat
 11     [ "7ef0742612e4db668ea2a7b5779f69cf"
 12     , "13762b48d36812fd72eda69207460a71"
 13     , "d2e2c901b8f46991249bd566e98b9e2b"
 14     , "31e897029c54c20f57a31e8e23f452f"
 15     ]
 16 
 17 hexToFour :: Char -> [Char]
 18 hexToFour '0' = "00"
 19 hexToFour '1' = "01"
 20 hexToFour '2' = "02"
 21 hexToFour '3' = "03"
 22 hexToFour '4' = "10"
 23 hexToFour '5' = "11"
 24 hexToFour '6' = "12"
 25 hexToFour '7' = "13"
 26 hexToFour '8' = "20"
 27 hexToFour '9' = "21"
 28 hexToFour 'a' = "22"
 29 hexToFour 'b' = "23"
 30 hexToFour 'c' = "30"
 31 hexToFour 'd' = "31"
 32 hexToFour 'e' = "32"
 33 hexToFour 'f' = "33"
 34 hexToFour c = error ("Not a hex digit" ++ [c])
 35 
 36 fourToHex :: String -> Char
 37 fourToHex "00" = '0'
 38 fourToHex "01" = '1'
 39 fourToHex "02" = '2'
 40 fourToHex "03" = '3'
 41 fourToHex "10" = '4'
 42 fourToHex "11" = '5'
 43 fourToHex "12" = '6'
 44 fourToHex "13" = '7'
 45 fourToHex "20" = '8'
 46 fourToHex "21" = '9'
 47 fourToHex "22" = 'a'
 48 fourToHex "23" = 'b'
 49 fourToHex "30" = 'c'
 50 fourToHex "31" = 'd'
 51 fourToHex "32" = 'e'
 52 fourToHex "33" = 'f'
 53 fourToHex c = error ("Not expected kubgen fourSet" ++ c)
 54 
 55 fourHash :: String -> String
 56 fourHash = concatMap hexToFour
 57 
 58 hash4 :: String
 59 hash4 = fourHash hsh
 60 
 61 plainText :: String
 62 plainText = "here is some different text"
 63 
 64 plainLen :: Int
 65 plainLen = length plainText
 66 
 67 mixy119 :: [Char] -> Int
 68 mixy119 x = mod (sum $ map fromEnum x) 119
 69 -- or from chatGPT: mixy119 = (`mod` 119) . sum . map fromEnum
 70 
 71 mixVal :: Int
 72 mixVal = mixy119 plainText
 73 
 74 hash4Val :: Int -> Int
 75 hash4Val x = fromEnum (hash4 !! x) - fromEnum '0'
 76 
 77 plainVal :: Int -> Int
 78 plainVal x = fromEnum (plainText !! x)
 79 
 80 churn :: Int -> Int
 81 churn x = mod (mixVal + (hash4Val (mod (x +mixVal) 127)) +
 82     plainVal (mod x plainLen) + 1) 4
 83 
 84 churnHash :: String
 85 churnHash = concatMap (show . churn) [0..255]
 86 
 87 pairs :: String -> [String]
 88 pairs [] = []
 89 pairs (x:y:xs) = [x, y] : pairs xs
 90 pairs _ = error "pairs: odd-length string"
 91 
 92 churnHex :: String
 93 churnHex = map fourToHex (pairs churnHash)
 94 
 95 krows :: String -> [String]
 96 krows [] = []
 97 krows xs = take 16 xs : krows (drop 16 xs)
 98 
 99 --main = mapM_ putStrLn (krows churnHash)
100 
101 glyph :: Char -> Char
102 glyph '0' = ' '
103 glyph '1' = '.'
104 glyph '2' = 'o'
105 glyph '3' = '#'
106 glyph  _  = '?'
107 
108 kpicture :: String
109 kpicture = map glyph churnHash
110 
111 --main = mapM_ putStrLn (krows kpictire)