cbase - 快速進制轉換
以下是自己寫的小程式cbase介紹,主要是用來進行數字的基底轉換,比如說10進位轉16進位。但是比較特別的是,cbase可以支援到256進位,當然有特殊的方法來分辨大於36進位的數字,前36進位是利用,0-9 a-z來表示的。至於寫這個程式的動機呢?因為假如在Linux上用iwconfig設定無線網路的話,WEP密碼必須使用16進位,這時候如果自己轉就很麻煩了。可是用cbase:
cbase -i a -o 16 WEP_KEY
輸出:
WEP_KEY (a) = 5745505f4b4559 (16)
然後就可以很方便的得到16進位字串了!
查某個字母的ASCII code也很方便,decode unicode也可以
cbase -i a -o 10 A #get ascii
cbase -i 16 -o a -do '%' -so [unicode_string] #decode unicode
輸出:
A (a) = 65 (10)
還有另一個動機是,看到有人可以把網址加上@然後後面接十進位IP,就可以忽略前面的網址,導向後面那個十進位IP所在的位址。於是我想如果可以把十進位的IP先轉回正常IP,那我就可以先知道會被連到哪裡啦?(當然逆向也可以)
舉例:
cbase -i 10 -o 256 2356152436
這樣會輸出:
2356152436 (10) = 140.112.008.116 (256)
於是IP就被還原了,這是因為其實IP可以看成一個256進位的數字所以可以這樣操作,至於詳細的用法自己看下面吧~
有人會想要用這個程式嗎?如果要的話回應一下吧,我再釋出原始碼。
是說這是我第一次寫比較完整的命令列程式,程式其實很簡單的,如果其他大大覺的我寫很爛的話,請你給我些意見吧XD
然後下面的help list可能有很多文法錯誤XDD 我完全靠殘餘的語感。
cbase -i a -o 16 WEP_KEY
輸出:
WEP_KEY (a) = 5745505f4b4559 (16)
然後就可以很方便的得到16進位字串了!
查某個字母的ASCII code也很方便,decode unicode也可以
cbase -i a -o 10 A #get ascii
cbase -i 16 -o a -do '%' -so [unicode_string] #decode unicode
輸出:
A (a) = 65 (10)
還有另一個動機是,看到有人可以把網址加上@然後後面接十進位IP,就可以忽略前面的網址,導向後面那個十進位IP所在的位址。於是我想如果可以把十進位的IP先轉回正常IP,那我就可以先知道會被連到哪裡啦?(當然逆向也可以)
舉例:
cbase -i 10 -o 256 2356152436
這樣會輸出:
2356152436 (10) = 140.112.008.116 (256)
於是IP就被還原了,這是因為其實IP可以看成一個256進位的數字所以可以這樣操作,至於詳細的用法自己看下面吧~
有人會想要用這個程式嗎?如果要的話回應一下吧,我再釋出原始碼。
是說這是我第一次寫比較完整的命令列程式,程式其實很簡單的,如果其他大大覺的我寫很爛的話,請你給我些意見吧XD
然後下面的help list可能有很多文法錯誤XDD 我完全靠殘餘的語感。
Usage: cbase [-i inbase] [-o outbase] [options] string1 string2 ... Argumets & options: -i [inbase] Inbase, the base of the given string. Base can range from 2 to 256, use 'a' to specify that the input string is alphabet. -o [inbase] Outbase, like inbase, but specify that the base of output string, use 'a' to specify the output string is alphabet. -d[i|o] DELIM use DELM as delimiter to identify each terms in the string. if DELM is not specified, '.' is used by default. -do: Tell cbase that the terms delimit by DELIM is processed rescpectively. For example: cbase -i 10 -o 16 -do ':' 97:98:99 will output 97:98:99 (10) = 61:62:63 (16) 97,98 and 99 are treated as 10-based number respectively, and processed repectively. -di: Tell cbase that the terms delimit by DELIM is treated as a single digit. This is often used when the base is larger than 36. For example: cbase -i 256 -o 10 -di 168.128.0.1 "168.128.0.1" is an IP address and can be treated as a 256-based number. However, no letters can represent such large number(Note: In cbase, 0-9a-z is used to present numbers whose base is less than 36), so DELIM is used to distinguish each digits for base larger than 36. For the example, the output is 168.128.0.1 (256) = 2826960897 (10) -g[i|o] COUNT The `-g' option is like the `-d' option, but instead of using delimiter, COUNT is used to group each terms. The example in `-do' can be repeated with the `-go' option. cbase -i 10 -o 16 -go 2 979899 will output 979899 (10) = 616263 (16) In the same manner, the second example with `-di' is repeated here with the `-gi' option: cbase -i 256 -o 10 -gi 3 168128000001 will output: 168128000001 (256) = 2826960897 (10) Note that you shound put '0' in front of '0', '1' to make than grouped in there, otherwise, cbase will to process the input. -f[i|o] The `-f' option is used to dilimit the string ouput. -fo: Delimit each term in the ouput string, this is especially useful when the `-g' or `-a' option is used. For example: cbase -i a -o 10 ntuee will output: ntuee (a) = 110116117101101 (10) but with the `-fo ':'` option, cbase will output. ntuee (a) = 110:116:117:101:101 (10) -fi: Like the `-fo` option, but will delimit the digits inside the term. For example: cbase -i a -o 10 -fo '|' -fi '.' ntuee will output: ntuee (a) = 1.1.0|1.1.6|1.1.7|1.0.1|1.0.1 (10) Note that, `-fi` option will be suppress when the ouput base is `a'. If it's no suppress, it will crash the output -s[i|o] Becaue if the `-do` option is specified, the output by default will delimit the string. the `-s' option is used the suppress the delimiter in the output string. For example: cbase -i 10 -o 256 -si 2826960897 Will output: 2826960897 (10) = 168128000001 (256) To decode unicode strings, the `-so' option must be used. For Example: cbase -i 16 -o a -do '%' -so [unicode_string] -v Show version information. -h Give this help list. By default, `-gi' option will not print out delimiter unless the base is greater than 36; `-do' option will print out delimiter, but you can suppress it by adding the `-so' option. Please report bugs to Aitjcize <aitjcize@gmail.com>
留言
我還很弱
這樣的程式你一定也寫得出來~
讓我想起你以前的綽號XDDDD