Advertisement
tdttvd

has-skill.hs

Nov 8th, 2023 (edited)
812
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 4.93 KB | Cybersecurity | 0 0
  1. import           Data.Bits
  2. import           Data.Char
  3. import           Data.Word
  4. import           System.IO
  5.  
  6. -- * returnValue for stringToWord32 "f4z3" = 1714715187
  7. stringToWord32 :: String -> Word32
  8. stringToWord32 s
  9.     | length s < 4 = error "What?"
  10.     | otherwise    = fromIntegral $
  11.                       (shiftL (ord (s !! 0)) 24) .|.
  12.                       (shiftL (ord (s !! 1)) 16) .|.
  13.                       (shiftL (ord (s !! 2)) 8)  .|.
  14.                       (ord (s !! 3))
  15.  
  16. key :: [Word32]
  17. key = [1714715187, 288574117, 2285509407, 4282198921, 1633271338, 375295676, 2404900614, 4166053776, 1760555521, 535347863, 2262930221, 4058424251, 1870804504, 411371150, 2173458228, 4136331170, 2072210007, 210000577, 2509048699, 3800710125, 2096016974, 199859928, 2464206690, 3857186804, 1968759397, 39834355, 2606138185, 3964777439, 1916085884, 87168746, 2621130576, 3946608582, 1566202619, 710765165, 3008642007, 3293776705, 1513594594, 758165108, 3023699918, 3275673432, 1401017033, 612819551, 3180311525, 3397944179, 1424758480, 602613318, 3135404028, 3454355306, 1089292959, 938113545, 2934123443, 3655605029, 1199607430, 814202384, 2844716970, 3733577532, 1312211629, 959574587, 2688066433, 3611267863, 1230702260, 1046230562, 2807392152, 3495057166, 283655075, 1743719221, 4276509327, 2313251353, 394657722, 1619185452, 4186676886, 2391584256, 506704785, 1765049095, 4030583485, 2268783147, 425621384, 1851344670, 4149221028, 2153195058, 224340935, 2052594513, 3813755627, 2488695421, 171110366, 2100682568, 3829174002, 2470166116, 59024373, 1954780003, 3985294041, 2592993871, 82405356, 1944999802, 3941009088, 2648716886, 730209131, 1551969277, 3314055751, 2995735249, 753655666, 1542254564, 3269836382, 3051523784, 626889561, 1381671887, 3411276405, 3159671523, 573593408, 1429694422, 3426629228, 3141076730, 909183759, 1094073241, 3628034595, 2939706037, 828165910, 1180434304, 3746737722, 2824183468, 954893117, 1340978091, 3605324305, 2716062343, 1065830180, 1216378802, 3515426312, 2794329758, 2341271827, 4237019525, 1703057471, 310749353, 2363571466, 4226157980, 1659853862, 367553712, 2237100321, 4065345975, 1800998925, 475930779, 2184885560, 4114449838, 1815401492, 456385666, 2520508791, 3778861537, 2016774235, 254982349, 2438344046, 3864075768, 2136493122, 140475604, 2564841797, 4024914387, 1995309161, 32059647, 2676860252, 3901396426, 1904460912, 109376742, 2967656923, 3353733453, 1592572151, 703301729, 3079609794, 3230149972, 1501658350, 780553336, 3191427561, 3376308607, 1345794245, 657457235, 3109328368, 3461588326, 1465578716, 543016010, 2908080575, 3662870825, 1130080403, 878483461, 2855800230, 3711909168, 1144417418, 858872860, 2744009101, 3565777179, 1300242593, 981930039, 2766374292, 3554981122, 1257104568, 1038799918, 4249925763, 2320992277, 324983215, 1683614009, 4198333594, 2369408012, 338894262, 1664363808, 4085985457, 2223767591, 495276445, 1786929419, 4108776616, 2212611134, 451450244, 1844421906, 3773278439, 2548078705, 250202571, 2045704541, 3884608766, 2425183336, 159649234, 2122530116, 3996917973, 2570784835, 3293689, 1999991151, 3914458316, 2656490586, 123700704, 1884861814, 3325990987, 2973346013, 674298215, 1597491697, 3243465810, 3058986180, 794639742, 1482296808, 3370455161, 3219267823, 652964181, 1374437827, 3481850976, 3096438006, 562476364, 1451328986, 3683223599, 2895034553, 898099459, 1115740565, 3705949238, 2883812512, 854207770, 1173167500, 3578920989, 2723491979, 995909937, 1281053095, 3527394308, 2771973266, 1009886504, 1261868478]
  18.  
  19. someHashFunction :: String -> Word32
  20. someHashFunction flag =
  21.     complement $
  22.     foldl foldFunction 0xffffffff (map (fromIntegral . ord) flag)
  23.  
  24. testFunc:: Word32 -> Word8 -> Word32
  25. testFunc a b = fromIntegral ((a `xor` fromIntegral b) .&. 0xFF)
  26.  
  27. foldFunction :: Word32 -> Word8 -> Word32
  28. foldFunction a b =
  29.     let
  30.         aXb = fromIntegral ((a `xor` fromIntegral b) .&. 0xFF)
  31.         returnValue = (a `shiftR` 8) `xor` (key !! fromIntegral aXb) `xor` stringToWord32("f4z3")
  32.     in
  33.         returnValue
  34.  
  35. x :: Int
  36. x = 214013
  37.  
  38. y :: Int
  39. y = 2531011
  40.  
  41. m :: Int
  42. m = 4294967296
  43.  
  44. someFunc :: Int -> Int
  45. someFunc hashedFlag = (x * hashedFlag + y) `mod` m
  46.  
  47. genArray :: Int -> Int -> [Int]
  48. genArray hashedFlag n
  49.     | n <= 0 = []
  50.     | otherwise = [((x * hashedFlag + y) `mod` m) `mod` 256] ++ genArray ((x * hashedFlag + y) `mod` m) (n - 1)
  51.  
  52. main :: IO ()
  53. main = do
  54.     putStr "Enter the flag: "
  55.     hFlush stdout
  56.     flag <- getLine
  57.  
  58.     let hashedFlag = someHashFunction flag
  59.  
  60.     let arr = genArray (fromIntegral hashedFlag) 58
  61.  
  62.     let result = [(ord (flag !! i)) `xor` (arr !! i) | i <- [0 .. 57]]
  63.  
  64.     putStrLn $ show result
  65.     if result == [185, 153, 4, 143, 108, 77, 73, 84, 208, 177, 6, 72, 59, 225, 184, 29, 20, 144, 46, 88, 19, 42, 136, 175, 129, 217, 49, 216, 203, 183, 6, 202, 168, 198, 129, 144, 182, 9, 179, 179, 119, 150, 185, 61, 168, 172, 26, 124, 135, 110, 196, 211, 62, 85, 165, 106, 234, 119]
  66.  
  67.     then putStrLn "Correct!"
  68.     else putStrLn "Try again..."
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement