-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.rkt
executable file
·36 lines (33 loc) · 1.12 KB
/
main.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#! /usr/bin/env racket
#lang racket/base
(require openssl/md5)
(require racket/cmdline)
(require racket/list)
(define (get-su-verification-code challenge)
((compose1 bytes->string/latin-1 list->bytes)
(map (lambda (x)
(let ([r2 (* (arithmetic-shift
(bitwise-and
(*
(arithmetic-shift x -1)
#xB60B60B7)
#xFFFFFFFF00000000)
-37)
90)])
(bitwise-and (+ (- x r2) #x21) #xFF))
)
(take
((compose1 bytes->list md5-bytes open-input-bytes)
(list->bytes
(map (lambda (b)
(arithmetic-shift b (if (<= b #x47) 1 -1)))
((compose1 bytes->list string->bytes/latin-1)
challenge))))
8))))
(command-line
#:program "huawei-su-verification-code"
#:args (challenge)
(if (= (string-length challenge) 8)
(displayln (get-su-verification-code challenge))
(displayln "Error: Challenge must have 8 chars!" (current-error-port)))
)