2021年9月23日 星期四

[Newsies] King of New York

matching: 適合的、相配的

box: 包廂

rye: 黑麥

nickle: 鎳幣

atcha: Slang for "at you"

lousy with: 有很多、充足的

stature: 地位、聲望

muckety mucks: 有地位、名聲的人(偏貶抑)

blow one's dough: 花光所有的錢

twirl: 轉、捻

barbershop: 理髮店

amscray: 閃開

poodle: 貴賓犬、奴才

fish out: 拖出

Flashpot: 閃光燈

highfalutin: 浮誇的

crap out: 使退場、出局

tapped out: 筋疲力盡

ditch: 丟棄、遺棄


本首歌使用大量當代的詞彙,有些生難字詞略過。

2021年9月13日 星期一

從code到encode/decode到base64

code

code,又稱碼。我們會把資訊用符號代替,這些符號就是碼。資訊科學常用到的是二元碼(binary code)

encode/decode

encode: 資訊 → 符號

decode: 符號 → 資訊

以ASCII為例,可以把字母轉換成相對應的數字(binary code)。

byte

一個byte用來儲存一個ASCII字元。

UTF-8

character to binary code

Base64

binary code to character


參考資料

https://web.ntnu.edu.tw/~algo/Code.html

看懂byte在幹嘛(python)

 假設我拿到了一個很長很長的byte sequence:
 b"*f\x97\xab&f-\x81ffff\x88f\xf67}@G\x06*\x97 \xab*6ff\xfe\x13\x0e\xebff\xbe\xeb\x81f[\x066\xec&\xee\xee\xfeI\xab\x97\xec\xc2\x06\x96\xa4P\xeb\xb9\x13\xfb\xebffff\xcbf/\x0f\x84f>\x0f\x0bf\xc2\x0f\x81\xa4\xe0\xebffff:6L\xabffff\xec\xecf\xcbffffffffffffffff\xecf\x0e\x93\x01fJ\x0b\xecf\xae\x93\x81f>\xbdffff%f+\xcb\x8efg\xee\x88ff\xcb*\xd3ff\x81f^\xbdffff\x15f+\xcb\x8ef\xe2\xee&f\x8e\xf1u\xec\x81\x11*e!f\x8ef\x97\xab*\xcb\x97fff\xc8\xf2\x8ef\x97\xab*\xcb\x97f\x88f\xf67\xfdSG\x06*\x97\xe0\xabl\xec\xc2\x06\x93f<\x0f\xa2f\x1a\x0fef\x05\x0f\xeefx\x0fLf\x8c\x0f\xf6f\xef\x0f\x0bfF\x0f\xcbf\x9e\x0f\x0b\xa4\xe0\xeb*\xbdJf*/\x97f\xecf\xef\x93\xecf\xe1\x93yf\x059:6L\xab\xec\xec\xcb\xee\xcbf\x9e\xeb\xabf\xcf\xcbfffftf\xd3\x0bffff\x93f<\xeb\xa2f\x1a\xebef\x05\xeb\xeefx\xebLf\x8c\xeb\xf6f\xef\xeb\x0bfF\xeb\x8ef\x97\xabNf\xc2\x06\x0b\xa4\xe0\xebffff:6L\xabffff\xcbf\x9e\xeb\x11f\xcf\xcbffff\x9af\xd3\x84ffff\xb1\xa4\xe0\xebffff:6L\xab*L\xd3\xad\xcbf\x9e\xebffff)\x13\xe0\xebffff:6L\xabffff\xcbf\x9e\xeb*L\xd3f\x86\xa4\xe0\xebffff:6L\xab:f\x88\xee\xcbf\x9e\xebffff\xd3\x13\xe0\xebffff:6L\xab*Lff\xe7\x13\xa4\xebffffff+\xbdffff\xd4\xech\x0bffff\xfd\xa4\xa4\xebffffff?"

該怎麼了解它呢?

首先,因為是byte,所以最前面有個b,並且字串頭尾被引號包起來。

再來會發現字串存在某種特殊pattern: 由斜線跟小寫字母x開頭,後面跟著兩個數字或字母組成的東西。

如果我們假設上面那串byte sequence叫做test,並且執行以下code:

for item in test:

    print(item)

會發現輸出好多整數。

奇怪,為什麼由字母、數字跟其他符號組成的字串,透過遍歷印出來,反而會得到整數數字呢?

所以我又撰寫以下code:

for i, item in enumerate(test):

    print("index {}: {} {}".format(i, test[i:(i+1)],item))

發現得到的輸出像是這樣:

index 0: b'*' 42
index 1: b'f' 102
index 2: b'\x97' 151
index 3: b'\xab' 171
index 4: b'&' 38
index 5: b'f' 102
index 6: b'-' 45
index 7: b'\x81' 129
index 8: b'f' 102
index 9: b'f' 102
index 10: b'f' 102
index 11: b'f' 102
index 12: b'\x88' 136
index 13: b'f' 102
index 14: b'\xf6' 246
index 15: b'7' 55

由於我們知道byte sequence嘛,顧名思義就是由一個個byte組成的長長一串,而byte本身就是以數字存在。上面的輸出結果表示對應的關係。

如果是\x開頭,代表是16進位,譬如 b'\x88' 就是16進位的byte,換算十進位則為136。

如果非\x開頭,對照ascii table會發現正好就是該字元與其ascii值對應。


參考文章

https://cloud.tencent.com/developer/article/1605567

2021年9月12日 星期日

[Newsies]Once and for All

once and for all: completely and finally

front-page: 頭版

snug: 舒適的

satin: 緞

thugs: 惡徒

slugs: (informal) 子彈

raise the stakes: 提高賭注、增加風險

brawl: 鬧事鬥毆

raring: 渴望急切的

sick of: 對...厭倦

play fair: to act in a fair and honest way

keep holding on: 不放棄

be gunning for: to often criticize someone or be trying to cause trouble for them

2021年9月11日 星期六

What is 'byte' in Python?

電腦以byte來儲存資料。

我們需要決定怎麼解讀byte,像是音樂、影像、文字等等使用的方法就不同,常見的有: PNG, JPG, ASCII, UTF-8。


在Python中byte string就是sequence of bytes,是人類讀不懂的。這麼做是為了把許多字元存起來。所以使用byte string前要先指定encode的方式,轉換成人類能夠理解的型態。

通常以b開頭,如: b'\xcf\x84o\xcf\x81\xce\xbdo\xcf\x82'

https://stackoverflow.com/questions/6224052/what-is-the-difference-between-a-string-and-a-byte-string


2021年9月9日 星期四

[Newsies] Seize the Day

seize the day: 把握當下

stare down: 以目光鎮懾某人

odds: 困難

battalion: (軍)營

Behold: 看

follow through: 堅持跟進

vow: 誓言

righted: 糾正 的過去式

draw near: 靠近

defiant: 挑釁的

All for one one for all: 我為人人 人人為我

Specs: 眼鏡

there'll be hell to pay: 會惹上大麻煩