Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Data.Bits
- import Data.Char
- import Data.Word
- import System.IO
- -- * returnValue for stringToWord32 "f4z3" = 1714715187
- stringToWord32 :: String -> Word32
- stringToWord32 s
- | length s < 4 = error "What?"
- | otherwise = fromIntegral $
- (shiftL (ord (s !! 0)) 24) .|.
- (shiftL (ord (s !! 1)) 16) .|.
- (shiftL (ord (s !! 2)) 8) .|.
- (ord (s !! 3))
- someRandNums :: [Word32]
- someRandNums = [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]
- someHashFunction :: String -> Word32
- someHashFunction flag =
- complement $
- foldl foldFunction 0xffffffff (map (fromIntegral . ord) flag)
- testFunc:: Word32 -> Word8 -> Word32
- testFunc a b = fromIntegral ((a `xor` fromIntegral b) .&. 0xFF)
- foldFunction :: Word32 -> Word8 -> Word32
- foldFunction a b =
- let
- aXb = fromIntegral ((a `xor` fromIntegral b) .&. 0xFF)
- returnValue = (a `shiftR` 8) `xor` (someRandNums !! fromIntegral aXb) `xor` stringToWord32("f4z3")
- in
- returnValue
- a :: Int
- a = 214013
- c :: Int
- c = 2531011
- m :: Int
- m = 4294967296
- someFunc :: Int -> Int
- someFunc hashedFlag = (a * hashedFlag + c) `mod` m
- genArray :: Int -> Int -> [Int]
- genArray x n
- | n <= 0 = []
- | otherwise = [((a * x + c) `mod` m) `mod` 256] ++ genArray ((a * x + c) `mod` m) (n - 1)
- main :: IO ()
- main = do
- putStr "Enter the flag: "
- hFlush stdout
- flag <- getLine
- let hashedFlag = someHashFunction flag
- let arr = genArray (fromIntegral hashedFlag) 58
- let result = [(ord (flag !! i)) `xor` (arr !! i) | i <- [0 .. 57]]
- 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]
- then putStrLn "Correct!"
- else putStrLn "Try again..."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement