├── ACL046100-example.zip ├── Packages └── 第三方模組 ├── Python2018 ├── BasicPython ├── week2 │ ├── Python_and_CTF │ └── advancedPython.md ├── week3_dataAnalysis.md ├── 一小時Python程式設計入門課{課綱} ├── 列表|串列(list)資料型態及其運算 ├── 字串(string)資料型態及其運算 └── 辭典|字典(dic)資料型態及其運算 ├── Python_books.md ├── README.md ├── STL ├── OS模組使用範例 └── sys模組使用範例 └── code_day1 ├── Calculator.py ├── if_test.py ├── my_XOR.py ├── new.py ├── new2.py ├── readme └── sys_test.py /ACL046100-example.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HappyHackingHigh/Python/d292cbddd9b2a2ebb47828958829fbc49cb71bea/ACL046100-example.zip -------------------------------------------------------------------------------- /Packages/第三方模組: -------------------------------------------------------------------------------- 1 | [6]第三方模組[1][2][3][4]5[6][7] 2 | 3 | 除了官方內建的程式庫之外,Python還有大量的第三方套件 4 | 5 | ------------------------------------- 6 | PyPI - the Python Package Index 7 | https://pypi.python.org/pypi 8 | PyPI是Python Package Index的縮寫,這是Python的第三方套件集中地, 9 | 目前蒐集了超過五萬個的第三方套件,幾乎所有能想像到的功能,都可以在這找到合適的套件。 10 | 11 | ------------------------------------- 12 | Python套件管理程式-pip 13 | pip是Python的套件管理工具,它集合下載、安裝、升級、管理、移除套件等功能, 14 | 藉由統一的管理,可以使我們事半功倍,更重要的是,也避免了手動執行上述任務會發生的種種錯誤。 15 | 16 | pip的安裝非常簡單,請前往pip的官方文件網站: 17 | http://pip.readthedocs.org/en/latest/installing.html 18 | 在install pip章節可以找到一個名為get-pip.py的檔案, 19 | 將內容複製到編輯器上再另存新檔, 20 | 接著在終端機中切換到get-pip.py的目錄並執行: 21 | $ python get-pip.py 22 | 23 | ------------------------------------- 24 | 使用pip: 25 | 26 | pip list #列出目前有安裝的套件 27 | pip help #列出pip的使用方式和指令 28 | pip help search #列出search指令的使用方式 29 | pip install XXXXX #安裝 30 | pip uninstall XXXXX #解除安裝 31 | pip install --upgrade XXXX #升級模組 32 | 33 | ============================================ 34 | Python常用模組 35 | 36 | 網站框架 37 | Django 完整而強大的Web框架,也就是這本書介紹的內容囉 38 | Pyramid 另一個完整強大的web框架 39 | web2py Google app engine預設使用的框架 40 | flask 相較於前三個是輕量的網站框架 41 | 42 | 圖片處理 43 | PIL 可對圖片進行縮放、切割、旋轉等各類操作 44 | Pillow 早先大家使用PIL,但年久失修後,出了一個fork的版本,就是Pillow 45 | 46 | 科學計算 47 | Numpy 支援非常多的科學計算,包含矩陣運算、線性代數、傅立葉轉換等。可說是集大成者,大多數科學計算套件皆有使用 48 | Matplotlib 可以畫出各種圖型如長條圖、分佈圖、立體圖等 49 | pandas 提供特殊資料結構,具有數據處理和資料分析的功能 50 | scikit-learn 機器學習的套件,包含內建的分群分類計算、回歸、統計等功能 51 | Tensorflow 52 | 53 | 命令列操作及遠端登入 54 | fabric 可以直接撰寫shell命令,透過fabric執行,也支援遠端登入和自定義shell命令 55 | paramiko 提供遠端登入和部分指令呼叫的功能 56 | 57 | 58 | 網路請求用戶端 59 | requests 可以模擬各種網路請求,如:get、post、put、delete等 60 | urllib 61 | urllib2 62 | pycurl 看名字便知道是在Linux、Unix系統上的命令:curl的python版本 63 | 64 | 網路爬蟲 65 | Scrapy Python爬蟲框架之一,可以輕易的與Django合作 66 | 67 | 文件剖析器 68 | beautifulsoup 可以處理HTML、XML等標記檔案 69 | lxml 可以處理HTML、XML等標記檔,使用xpath選取內容 70 | 71 | 72 | 自然語言處理(NLK) 73 | nltk 理論基礎及功能很強大的語言處理套件,但相對低階,需花一些時間熟悉才能流利使用 74 | textblob 較高階的分詞、分句、語言分析工具 75 | jieba 針對中文的分詞、分句、語言分析工具 76 | 77 | 背景程序、定時任務 78 | celery 可輕易地編寫、呼叫非同步及背景程序,或是執行定時任務(cronjob) 79 | 80 | 資料庫介接 81 | mysql-python MySQL資料庫介接套件,Django連接MySQL時預設使用的套件 82 | psycopg2 PostgreSQL資料庫介接套件,Django連接PostgreSQL時預設使用的套件 83 | pymongo MongoDB資料庫介接套件 84 | 85 | 加解密與破密分析常用模組 86 | pycrypto 87 | 88 | ------------------------------------- 89 | pycrypto 90 | pycrypto 2.6.1 91 | Cryptographic modules for Python. 92 | -------------------------------------------------------------------------------- /Python2018/BasicPython: -------------------------------------------------------------------------------- 1 | 一小時Python程式設計入門課 2 | 3 | http://120.114.62.89 4 | 5 | 龍大大 6 | ========================================= 7 | 為什麼要學Python? 8 | 如何學Python?打造你的學習地圖! 9 | 10 | ========================================= 11 | Python開發環境@windwos 12 | 下載python 13 | 安裝Python2.7==>裝在D:\python2 14 | 安裝Python3.6==>裝在D:\python3{記得改成python3} 15 | ------------------------------------------------------- 16 | [1]使用python interactive shell 17 | 進入python 18 | 在cmd輸入python==>進入 19 | 離開==>exit() 20 | ------------------------------------------------------- 21 | [2]使用notepad++寫程式==>記得檔名要XXX.py 22 | 執行: 23 | [1]進入你的程式目錄 D:\p3code (三年級) D:\p_code(一(年級) 24 | [2]D:\python2\python.exe XXX.py 25 | 或 D:\python3\python.exe XXX.py 26 | ------------------------------------------------------- 27 | ========================================= 28 | Python開發環境@Ubuntu 16.04 LTS 64-bit 29 | 30 | [1]使用python interactive shell 31 | 開啟terminal,輸入下列指令 32 | python==>進入python 2.7shell 33 | python3==>進入python 3.6.X shell 34 | 離開==>exit() 35 | ------------------------------------------------------- 36 | [2]使用gedit(或nano或vim)寫程式==>記得檔名要XXX.py 37 | python xxx.py 38 | python3 xxx.py 39 | 40 | ========================================= 41 | Python程式設計{基礎課程} 42 | 43 | [1]輸入與輸出 USER INPUTS AND OUTPUTS: 44 | [1.1]輸入:input | Raw_input 45 | raw_input([prompt]) 函數從標準輸入讀取一個行,並返回一個字串(去掉結尾的分行符號) 46 | input([prompt]) 函數和 raw_input([prompt]) 函數基本類似,但是 input 可以接收一個Python運算式作為輸入,並將運算結果返回。 47 | 48 | ------------------------------------------------ 49 | 50 | ------------------------------------------------ 51 | #!/usr/bin/env python 52 | #coding=utf-8 53 | 54 | # radius = 20 # radius is now 20 55 | # Prompt the user to enter a radius 56 | radius = eval(input("Enter a number for radius: ")) 57 | 58 | # Compute area 59 | area = radius * radius * 3.14159 60 | 61 | # Display results 62 | print("The area for the circle of radius", radius, "is", area) 63 | ------------------------------------------------ 64 | 65 | 同時指定(Simultaneous Assignment ) 66 | ------------------------------------------------ 67 | #!/usr/bin/env python 68 | #coding=utf-8 69 | # Prompt the user to enter three numbers 70 | number1, number2, number3 = eval(input( 71 | "Enter three numbers separated by commas: ")) 72 | 73 | # Compute average 74 | average = (number1 + number2 + number3) / 3 75 | 76 | # Display result 77 | print("The average of", number1, number2, number3, 78 | "is", average) 79 | ------------------------------------------------ 80 | 81 | 82 | [1.2]輸出:print 83 | ------------------------------------------------ 84 | [動手做]下列範例會產生何種結果 85 | >>> q = 259 86 | >>> p = 0.038 87 | >>> print(q, p, p * q) 88 | >>> print(q, p, p * q, sep=",") 89 | >>> print(q, p, p * q, sep=" :-) ") 90 | >>> print(str(q) + " " + str(p) + " " + str(p * q)) 91 | ------------------------------------------------ 92 | 93 | [1.3]格式化輸出Formatted Output 94 | [Further reading延伸閱讀]https://www.python-course.eu/python3_formatted_output.php 95 | 96 | 使用format() 97 | "{0} love {1}......{2}".format("I","listening","classical Music") 98 | 99 | 使用% 100 | '%c' % 97 101 | '%c %c %c %c %c ' % (97,98,99,100,101) 102 | '%d 八進位是%0 , 十六進位是 %x' % (97,97, 97) 103 | 104 | 符 號 描述 105 | %c 格式化字元及其ASCII碼 106 | %s 格式化字串 107 | %d 格式化整數 108 | %u 格式化無符號整型 109 | %o 格式化無符號八進位數 110 | %x 格式化無符號十六進位數 111 | %X 格式化無符號十六進位數(大寫) 112 | %f 格式化浮點數字,可指定小數點後的精度 113 | %e 用科學計數法格式化浮點數 114 | %E 作用同%e,用科學計數法格式化浮點數 115 | %g %f和%e的簡寫 116 | %G %f 和 %E 的簡寫 117 | %p 用十六進位數格式化變數的位址 118 | 119 | [1.4]運算子 120 | 餘數運算子 (remainder|modulo) 121 | ------------------------------------------------ 122 | 以秒表示的總時間長,取得分鐘數及剩餘的秒數。 123 | ------------------------------------------------ 124 | #!/usr/bin/env python 125 | #coding=utf-8 126 | 127 | seconds = eval(input("Enter an integer for seconds: ")) 128 | 129 | minutes = seconds // 60 # Find minutes in seconds 130 | remainingSeconds = seconds % 60 # Seconds remaining 131 | print(seconds, "seconds is", minutes, 132 | "minutes and", remainingSeconds, "seconds") 133 | ------------------------------------------------ 134 | 135 | [2]各種資料型態及其運算[1][2][3][4]...[X] 136 | 137 | 數字型(numeric)資料型態及其運算 138 | 字串(string)資料型態及其運算 139 | 列表|串列(list)資料型態及其運算 140 | 辭典|字典(dic)資料型態及其運算 141 | ……………… 142 | 143 | [3]迴圈與選擇 144 | 迴圈::while | for loop |沒有do-while |range|break|continue 145 | ------------------------------------------------------- 146 | 選擇:If |if-else| ..沒有switch 147 | 148 | [3.1]選擇:If |if-else| ..沒有switch 149 | ------------------------------------------------------- 150 | #猜數字游戲_版本一 151 | #!/usr/bin/python 152 | # -*- coding: UTF-8 -*- 153 | 154 | number = 2315698 155 | 156 | guess = int(raw_input('Enter an integer : ')) 157 | 158 | if guess == number: 159 | print 'Congratulations, you guessed it.' 160 | print "(This is flag: BreakALL{It is easy to write if statement}!)" 161 | elif guess < number: 162 | print 'No, it is a little higher than that' 163 | # You can do whatever you want in a block ... 164 | else: 165 | print 'No, it is a little lower than that' 166 | # you must have guess > number to reach here 167 | 168 | print 'Done' 169 | 170 | ------------------------------------------------------- 171 | #!/usr/bin/python 172 | # -*- coding: UTF-8 -*- 173 | print("") 174 | print("西元年代對應到的十二生肖") 175 | print("") 176 | year = eval(input("請輸入你出生的年代: ")) 177 | print("") 178 | zodiacYear = year % 12 179 | if zodiacYear == 0: 180 | print("monkey===猴子哩") 181 | elif zodiacYear == 1: 182 | print("rooster雞") 183 | elif zodiacYear == 2: 184 | print("dog狗狗") 185 | elif zodiacYear == 3: 186 | print("pig豬豬") 187 | elif zodiacYear == 4: 188 | print("rat鼠") 189 | elif zodiacYear == 5: 190 | print("ox牛") 191 | elif zodiacYear == 6: 192 | print("tiger虎虎生威") 193 | elif zodiacYear == 7: 194 | print("rabbit兔子") 195 | elif zodiacYear == 8: 196 | print("dragon偉大的龍") 197 | elif zodiacYear == 9: 198 | print("snake蛇") 199 | elif zodiacYear == 10: 200 | print("horse馬") 201 | else: 202 | print("sheep羊") 203 | ------------------------------------------------------- 204 | 205 | [3.2]for loop 206 | 207 | ------------------------------------------------------- 208 | words = ['cat', 'window', 'defenestrate'] 209 | for w in words: 210 | print w, len(w) 211 | ------------------------------------------------------- 212 | #!/usr/bin/python 213 | # -*- coding: UTF-8 -*- 214 | 215 | for i in range(1,5): 216 | for j in range(1,5): 217 | for k in range(1,5): 218 | if( i != k ) and (i != j) and (j != k): 219 | print i,j,k 220 | ------------------------------------------------------- 221 | ================================================================ 222 | 【Python 練習實例81】 223 | 題目:809*??=800*??+9*?? 其中??代表的兩位數, 809*??為四位數, 224 | 8*??的結果為兩位數,9*??的結果為3位數。 225 | 求??代表的兩位數,及809*??後的結果。 226 | ================================================================ 227 | #!/usr/bin/python 228 | # -*- coding: UTF-8 -*- 229 | 230 | a = 809 231 | for i in range(10,100): 232 | b = i * a 233 | if b >= 1000 and b <= 10000 and 8 * i < 100 and 9 * i >= 100: 234 | print b,' = 800 * ', i, ' + 9 * ', i 235 | ------------------------------------------------------------------ 236 | 237 | 238 | 239 | [3.3]while 迴圈 240 | 241 | ------------------------------------------------------- 242 | #猜數字游戲_版本二:Python3 243 | #!/usr/bin/env python 244 | #coding=utf-8 245 | 246 | from __future__ import print_function 247 | 248 | import random 249 | 250 | x = random.randint(1,100) 251 | 252 | while (1): 253 | number = int(input("猜數字,輸入一個數字:")) 254 | if x == number: 255 | print("您猜對了!") 256 | print(“獎品是 BreakALL{you have done a good guess}") 257 | break 258 | elif x > number: 259 | print("比",number,"大") 260 | elif x < number: 261 | print("比",number,"小") 262 | 263 | 264 | [程式開發作業]最大公因數 265 | 266 | -------------------------------- 267 | [3.3]range 268 | range(start, stop[, step]) 269 | 270 | [動手做]下列範例會產生何種結果 271 | 範例:range(100) 272 | 範例:range(1, 101) 273 | 範例:range(0, 10, 2) 274 | 範例:range(0, -10, -1) 275 | 276 | >>>x = 'BreakALL' 277 | >>> for i in range(len(x)) : 278 | ... print(x[i]) 279 | -------------------------------- 280 | #!/usr/bin/python 281 | # -*- coding: UTF-8 -*- 282 | 283 | tmp = 0 284 | for i in range(1,101): 285 | tmp += i 286 | print 'The sum is %d' % tmp 287 | -------------------------------- 288 | ================================================================ 289 | 【Python 練習實例30】 290 | 輸入一個5位數,判斷它是不是回文數。 291 | 12321是回文數,個位與萬位相同,十位與千位相同。 292 | ================================================================ 293 | #!/usr/bin/python 294 | # -*- coding: UTF-8 -*- 295 | 296 | a = int(raw_input("請輸入一個數字:\n")) 297 | x = str(a) 298 | flag = True 299 | 300 | for i in range(len(x)/2): 301 | if x[i] != x[-i - 1]: 302 | flag = False 303 | break 304 | if flag: 305 | print "%d 是一個回文數!" % a 306 | else: 307 | print "%d 不是一個回文數!" % a 308 | ------------------------------------------------------------ 309 | 310 | -------------------------------- 311 | nested loop 巢狀迴圈 312 | [程式開發作業]99乘法表 313 | 314 | 315 | 316 | [4]函式/函數/function 317 | 函數是組織好的,可重複使用的,用來實現單一,或相關聯功能的程式碼片段。 318 | 函數能提高應用的模組性,和代碼的重複利用率。 319 | Python提供了許多內建函數,比如print()。 320 | 使用者也可以自己創建函數,這被叫做使用者自訂函數。 321 | 322 | 定義一個函數 323 | 你可以定義一個由自己想要功能的函數,以下是簡單的規則: 324 | 函數代碼塊以 def 關鍵字開頭,後接函數識別字名稱和圓括號()。 325 | 任何傳入參數和引數必須放在圓括號中間。圓括號之間可以用於定義參數。 326 | 函數的第一行語句可以選擇性地使用文檔字串—用於存放函數說明。 327 | 函數內容以冒號起始,並且縮進。 328 | return [運算式] 結束函數,選擇性地返回一個值給調用方。不帶運算式的return相當於返回 None。 329 | 330 | 語法 331 | def functionname( parameters ): 332 | "函數_文檔字串" 333 | function_suite 334 | return [expression] 335 | 336 | ================================================================ 337 | 【Python 練習實例47】練習撰寫函式swap(a,b) 338 | 寫一個函式將輸入的兩個變數值互換 339 | ================================================================ 340 | #!/usr/bin/python 341 | # -*- coding: UTF-8 -*- 342 | 343 | def swap(a,b): 344 | a,b = b,a 345 | return (a,b) 346 | 347 | if __name__ == '__main__': 348 | x = 10 349 | y = 20 350 | print 'x = %d,y = %d' % (x,y) 351 | x,y = swap(x,y) 352 | print 'x = %d,y = %d' % (x,y) 353 | --------------------------------------------------------- 354 | 355 | ----------------------------- 356 | #!/usr/bin/python 357 | # -*- coding: UTF-8 -*- 358 | 359 | def crypt(source, key): 360 | from itertools import cycle 361 | result = '' 362 | temp = cycle(key) 363 | for ch in source: 364 | result = result + chr(ord(ch) ^ ord(next(temp))) 365 | return result 366 | 367 | source = 'BreakALLCTF_IknowhowtoXORRRRing' 368 | key = 'HappyHackingHigh' 369 | 370 | print('未加密的明文:'+source) 371 | encrypted = crypt(source, key) 372 | print('加密過的密文:'+encrypted) 373 | decrypted = crypt(encrypted, key) 374 | print('解密過的答案:'+decrypted) 375 | print('使用的金鑰:'+ key) 376 | ----------------------------- 377 | 378 | ----------------------------- 379 | [Further reading延伸閱讀] 380 | http://python3-cookbook.readthedocs.io/zh_CN/latest/chapters/p07_functions.html 381 | 可接受任意數量參數的函數 382 | 只接受關鍵字參數的函數 383 | 給函數參數增加元資訊 384 | 返回多個值的函數 385 | 定義有預設參數的函數 386 | 定義匿名或內聯函數 387 | 匿名函數捕獲變數值 388 | 減少可調用物件的參數個數 389 | 將單方法的類轉換為函數 390 | 帶額外狀態資訊的回呼函數 391 | 內聯回呼函數 392 | 訪問閉包中定義的變數 393 | ----------------------------- 394 | [4.2]遞迴函式==recursive vs iterative(loop) 395 | [程式開發作業]費氏數列 396 | [程式開發作業]n! 397 | [程式開發作業]河內塔 398 | 399 | ========================================= 400 | [程式開發作業] 401 | 費氏數列Fibonacci sequence:recursive vs iterative(loop) 402 | 又稱黃金分割數列 403 | 0、1、1、2、3、5、8、13、21、34、……。 404 | 在數學上,費波那契數列是以遞迴的方法來定義: 405 | F(0) = 0 (n=0) 406 | F(1) = 1 (n=1) 407 | F(n) = F(n-1)+ F(n-2)(n=>2) 408 | ========================================= 409 | ----------------------------- 410 | #!/usr/bin/python 411 | # -*- coding: UTF-8 -*- 412 | 413 | def fib(n): 414 | a,b = 1,1 415 | for i in range(n-1): 416 | a,b = b,a+b 417 | return a 418 | 419 | print fib(10) 420 | ----------------------------- 421 | #!/usr/bin/python 422 | # -*- coding: UTF-8 -*- 423 | 424 | def fib(n): 425 | if n==1 or n==2: 426 | return 1 427 | return fib(n-1)+fib(n-2) 428 | 429 | print fib(10) 430 | ----------------------------- 431 | ================================================================ 432 | 【Python 練習實例28】 433 | 有5個人坐在一起, 434 | 問第五個人多少歲?他說比第4個人大2歲。 435 | 問第4個人歲數,他說比第3個人大2歲。 436 | 問第三個人,又說比第2人大兩歲。 437 | 問第2個人,說比第一個人大兩歲。 438 | 最後問第一個人,他說是10歲。 439 | 請問第五個人多大? 440 | ================================================================ 441 | 442 | 443 | ----------------------------- 444 | [4.3]匿名函式及lambda運算式 445 | ----------------------------- 446 | 447 | [4.4]python內建函式Built-in Functions: 448 | https://docs.python.org/2/library/functions.html 449 | 450 | dir(__builtins__) 451 | help('math') 452 | help(id) 453 | 454 | import sys 455 | print(system.builtin_module_names) 456 | ---------------------- 457 | Ascii code 458 | https://zh.wikipedia.org/wiki/ASCII 459 | ord('a') 460 | chr(97) 461 | chr(ord('A')+1) 462 | ---------------------- 463 | 464 | [4.5]使用函式來模組化程式 465 | 函式可用來減少多餘的程式碼,允許程式碼重複使用,還可以用來模組化程式碼,提升程式品質 466 | 467 | 步驟一:先將常用的功能寫成函式MyGCD.py 468 | ----------------------------- 469 | #!/usr/bin/python 470 | # -*- coding: UTF-8 -*- 471 | # Return the gcd of two integers 472 | def gcd(n1, n2): 473 | gcd = 1 # Initial gcd is 1 474 | k = 2 # Possible gcd 475 | 476 | while k <= n1 and k <= n2: 477 | if n1 % k == 0 and n2 % k == 0: 478 | gcd = k # Update gcd 479 | k += 1 480 | 481 | return gcd # Return gcd 482 | 483 | ----------------------------- 484 | 步驟二:在主程式呼叫函式MyGCD.py 485 | ----------------------------- 486 | #!/usr/bin/python 487 | # -*- coding: UTF-8 -*- 488 | 489 | from MyGCD import gcd # 載入要用的模組 490 | 491 | # 請使用者輸入兩個整數 492 | n1 = eval(input("請輸入第一個整數: ")) 493 | n2 = eval(input("請輸入第二個整數 ")) 494 | 495 | # 輸出兩個整數的最大公因數 496 | print("兩個整數的最大公因數", n1, 497 | "and", n2, "is", gcd(n1, n2)) 498 | ----------------------------- 499 | 500 | 501 | [5]標準函式庫The Python Standard Library[1][2][3][4]5[6][7] 502 | https://docs.python.org/2/library/index.html 503 | 無須安裝,但要import 504 | 505 | binascii: 506 | base64::是一種任意二進位到文本字串的編碼方法,常用於在URL、Cookie、網頁中傳輸少量二進位資料 507 | https://docs.python.org/2/library/base64.html#module-base64 508 | hashlib::提供了常見的雜湊演算法,如MD5,SHA1 509 | 510 | ------------------------------------- 511 | import time 512 | import math 513 | 514 | start = time.time() #取得目前時間 515 | for i in range(10000000): 516 | math.sin(i) 517 | print('Time Used:', time.time()-start) #輸出所耗時間 518 | ------------------------------------- 519 | import hashlib 520 | 521 | a = ‘HappyCTF{It is FUN hashing with python hashlib}’ 522 | 523 | print hashlib.md5(a).hexdigest() 524 | print hashlib.sha1(a).hexdigest() 525 | print hashlib.sha224(a).hexdigest() 526 | print hashlib.sha256(a).hexdigest() 527 | print hashlib.sha384(a).hexdigest() 528 | print hashlib.sha512(a).hexdigest() 529 | ------------------------------------- 530 | =============================================================================== 531 | Base64編碼與解碼 532 | https://zh.wikipedia.org/wiki/Base64 533 | =============================================================================== 534 | import base64 535 | s = ‘FunnyCTF{BasE64 encoding is fufufufun!}' 536 | a = base64.b64encode(s) 537 | print a 538 | print base64.b64decode(a) 539 | c = base64.b32encode(s) 540 | print c 541 | print base64.b32decode(c) 542 | 543 | =============================================================================== 544 | 使用binascii — Convert between binary and ASCII 545 | 二進位|十進位|十六進位與ASCII互換的好模組 546 | https://docs.python.org/2/library/binascii.html 547 | 548 | binascii.b2a_hex(data) || binascii.hexlify(data) 549 | Return the hexadecimal representation of the binary data. 550 | Every byte of data is converted into the corresponding 2-digit hex representation. 551 | The resulting string is therefore twice as long as the length of data. 552 | 553 | binascii.a2b_hex(hexstr) || binascii.unhexlify(hexstr) 554 | Return the binary data represented by the hexadecimal string hexstr. 555 | This function is the inverse of b2a_hex(). 556 | hexstr must contain an even number of hexadecimal digits 557 | (which can be upper or lower case), otherwise a TypeError is raised. 558 | =============================================================================== 559 | 560 | #coding:utf-8 561 | import binascii 562 | a = ‘HappyCTF{Useful tools binascii}' 563 | b = binascii.b2a_hex(a) 564 | print b 565 | print binascii.a2b_hex(b) 566 | c = binascii.hexlify(a) 567 | print c 568 | print binascii.unhexlify(c) 569 | ------------------------------------- 570 | 571 | [6]第三方模組[1][2][3][4]5[6][7]......[X] 572 | 需要安裝,也要import 573 | 574 | PyPI - the Python Package Index 575 | https://pypi.python.org/pypi 576 | ------------------------------------- 577 | 安裝模組: 578 | pip list 579 | pip install XXXXX 580 | pip uninstall XXXXX 581 | pip install --upgrade XXXX #升級模組 582 | ------------------------------------- 583 | pycrypto 584 | pycrypto 2.6.1 585 | Cryptographic modules for Python. 586 | 587 | 588 | [7]各種類型檔案存取[1][2][3][4]5[6][7] 589 | 590 | ============================================= 591 | 【Python 練習範例98】 592 | 從鍵盤輸入一個字串,將小寫字母全部轉換成大寫字母, 593 | 然後輸出到一個檔"test"中保存。 594 | Python 2.7:OK 595 | Python 3.6 596 | ============================================= 597 | #!/usr/bin/python 598 | # -*- coding: UTF-8 -*- 599 | 600 | if __name__ == '__main__': 601 | fp = open('test.txt','w') 602 | string = raw_input('please input a string:\n') 603 | string = string.upper() 604 | fp.write(string) 605 | fp = open('test.txt','r') 606 | print fp.read() 607 | fp.close() 608 | 609 | ============================================= 610 | if __name__ == '__main__' 如何正确理解? 611 | https://www.zhihu.com/question/49136398 612 | ============================================= 613 | 614 | ============================================= 615 | 參考資料: 616 | [1]Python Cookbook 3rd Edition Documentation 617 | http://python3-cookbook.readthedocs.io/zh_CN/latest/index.html 618 | 619 | [2] 620 | https://www.python-course.eu/python3_modules_and_modular_programming.php 621 | 622 | [3]Python Documentation contents 623 | https://docs.python.org/3/contents.html 624 | https://docs.python.org/2/contents.html 625 | 626 | [5]Python Essential Reference, 5th Edition 627 | https://forum.dabeaz.com/t/python-essential-reference-5th-edition/145 628 | -------------------------------------------------------------------------------- /Python2018/week2/Python_and_CTF: -------------------------------------------------------------------------------- 1 | python程式與CTF 2 | 3 | Python編碼與解碼 4 | Python與破密分析 5 | Python與WEB 6 | Python與逆向工程 7 | python程式編譯與反編譯 8 | Python與PWN 9 | 10 | Python編碼與解碼 11 | ASCII 12 | Base64 13 | Base32 14 | 15 | python程式設計與破密分析 16 | 17 | 破密分析 18 | 19 | 古典密碼學 20 | [1]Substitution ciphers 替換加密 21 | https://en.wikipedia.org/wiki/Substitution_cipher 22 | 23 | [1.1]Monoalphabetic substitution 24 | 25 | 凱撒密碼Caesar cipher(ROT13) [https://en.wikipedia.org/wiki/Caesar_cipher] 26 | Affine cipher    Atbash cipher  Keyword cipher 27 | 28 | [1.2]Polyalphabetic substitution 29 | Vigenère cipher (https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher) 30 | Autokey cipher 31 | Homophonic substitution cipher 32 | 33 | [1.3]Polygraphic substitution 34 | Playfair cipher    Hill cipher 35 | 36 | [2]Transposition ciphers 換位加密法 37 | https://en.wikipedia.org/wiki/Transposition_cipher 38 | 39 | Rail Fence cipher      Route cipher 40 | Scytale 41 | Grille 42 | Permutation cipher 43 | VIC cipher 44 | ------------------------------- 45 | RSA公開金鑰 46 | ------------------------------- 47 | Cipher Tools 48 | http://rumkin.com/tools/cipher/ 49 | ------------------------------- 50 | ============================== 51 | Python開發環境 52 | 安裝Python2.7==>裝在D:\python27 53 | 安裝Python3.6==>裝在D:\python3{記得改成python3} 54 | 55 | 56 | import sys 57 | import hashlib 58 | import os.path 59 | 60 | filename = sys.argv[1] 61 | if os.path.isfile(filename): 62 | fp = open(filename, 'rb') 63 | contents = fp.read() 64 | fp.close() 65 | print(hashlib.md5(contents).hexdigest()) 66 | else: 67 | print('file not exists') 68 | -------------------------------------------------------------------------------- /Python2018/week2/advancedPython.md: -------------------------------------------------------------------------------- 1 | # Python進階技術 2 | 3 | 函數的進階技術 4 | 5 | 函數參數傳遞 6 | 7 | 高階函數 8 | 9 | 函數map()、filter()和reduce() 10 | 11 | Lambda運算式 12 | 13 | 關鍵字global 14 | 15 | 函數的遞歸 16 | 17 | ### 迭代器與生成器 18 | 19 | 迭代器 20 | 21 | 生成器 22 | 23 | ### 裝飾器 24 | 25 | 裝飾器的引入 26 | 27 | 裝飾器的用法 28 | 29 | ### 上下文管理器與with語句 30 | 31 | 上下文管理器的原理 32 | 33 | 模組contextlib 34 | 35 | ### 變數作用域 36 | 37 | 38 | # Python標準庫 39 | 40 | 系統相關:sys模組 41 | 42 | 與作業系統進行互動:os模組 43 | 44 | 字串相關:string模組 45 | 46 | 正則運算式:re模組 47 | 48 | 日期時間相關:datetime模組 49 | 50 | 更好地列印Python對象:pprint模組 51 | 52 | 序列化Python對象:pickle,cPickle模組 53 | 54 | 讀寫JSON數據:json模組 55 | 56 | 檔模式匹配:glob模組 57 | 58 | 高級檔操作:shutil模組 59 | 60 | 更多的容器類型:collections模組 61 | 62 | 數學:math模組 63 | 64 | 亂數:random模組 65 | 66 | # P物件導向技術 67 | -------------------------------------------------------------------------------- /Python2018/week3_dataAnalysis.md: -------------------------------------------------------------------------------- 1 | 2 | ``` 3 | 4 | ``` 5 | 6 | # PythonNumPy模組 7 | 5.1 NumPy模組簡介162 8 | 5.2 數組基礎163 9 | 5.2.1 數組的引入163 10 | 5.2.2 數組的屬性164 11 | 5.2.3 數組的類型166 12 | 5.2.4 數組的生成169 13 | 5.2.5 數組的索引172 14 | 5.2.6 數組的迭代174 15 | 5.3 數組操作175 16 | 5.3.1 數值相關的數組操作175 17 | 5.3.2 形狀相關的數組操作179 18 | 5.3.3 數組的拼接操作184 19 | 5.3.4 數組的四則運算、點乘和矩陣類型187 20 | 5.3.5 數組的數學操作190 21 | 5.3.6 數組的比較和邏輯操作190 22 | 5.4 數組廣播機制191 23 | 5.5 數組索引進階194 24 | 5.5.1 數組基礎索引194 25 | 5.5.2 數組的高級索引196 26 | 5.6 數組讀寫199 27 | 5.6.1 數組的讀取199 28 | 5.6.2 數組的寫入200 29 | 5.6.3 數組的二進位讀寫200 30 | 5.7 亂數組202 31 | 5.8 結構數組202 32 | 本章學習筆記206 33 | 本章新術語207 34 | 本章新函數207 35 | 第6章 Python可視化:Matplotlib模組209 36 | 6.1 Matplotlib模組簡介209 37 | 6.2 基於函數的可視化操作210 38 | 6.2.1 函數plt.plot()的使用210 39 | 6.2.2 圖與子圖215 40 | 6.2.3 其他可視化函數217 41 | 6.3 基於對象的可視化操作217 42 | 6.4 圖像中的文本處理219 43 | 6.5 實例:基於Matplotlib的三角函數可視化221 44 | 本章學習筆記226 45 | 本章新術語227 46 | 本章新函數227 47 | 第7章 Python科學計算進階:SciPy模組228 48 | 7.1 SciPy模組簡介228 49 | 7.2 插值模組:scipy.interpolate229 50 | 7.3 概率統計模組:scipy.stats233 51 | 7.3.1 基本統計量233 52 | 7.3.2 概率分佈234 53 | 7.3.3 假設檢驗243 54 | 7.4 優化模組:scipy.optimize246 55 | 7.4.1 數據擬合247 56 | 7.4.2 最值優化251 57 | 7.4.3 方程求根254 58 | 7.5 積分模組:scipy.integrate255 59 | 7.5.1 符號積分與SymPy模組255 60 | 7.5.2 數值積分257 61 | 7.6 稀疏矩陣模組:scipy.sparse260 62 | 7.7 線性代數模組:scipy.linalg262 63 | 7.8 實例:基於SciPy的主成分分析268 64 | 本章學習筆記271 65 | 本章新術語272 66 | 本章新函數272 67 | 第8章 Python數據分析基礎:Pandas模組274 68 | 8.1 Pandas簡介274 69 | 8.2 一維數據結構:Series對象275 70 | 8.2.1 Series對象的生成275 71 | 8.2.2 Series對象的使用277 72 | 8.3 二維數據結構:DataFrame對象280 73 | 8.3.1 DataFrame對象的生成280 74 | 8.3.2 DataFrame對象的使用283 75 | 8.4 Pandas對象的索引286 76 | 8.4.1 基於中括弧的索引和切片286 77 | 8.4.2 基於位置和標記的高級索引289 78 | 8.5 缺失值的處理293 79 | 8.6 數據的讀寫294 80 | 8.7 實例:基於Pandas的NBA數據分析295 81 | -------------------------------------------------------------------------------- /Python2018/一小時Python程式設計入門課{課綱}: -------------------------------------------------------------------------------- 1 | 一小時Python程式設計入門課 2 | 3 | 龍大大 4 | ========================================= 5 | 為什麼要學Python? 6 | 如何學Python?打造你的學習地圖! 7 | Python開發環境 8 | ========================================= 9 | Python程式設計{基礎課程} 10 | 11 | [1]輸入與輸出 USER INPUTS AND OUTPUTS: 12 | 輸入:input | Raw_input 13 | raw_input([prompt]) 函數從標準輸入讀取一個行,並返回一個字串(去掉結尾的分行符號) 14 | input([prompt]) 函數和 raw_input([prompt]) 函數基本類似,但是 input 可以接收一個Python運算式作為輸入,並將運算結果返回。 15 | 16 | 輸出:print 17 | 18 | 格式化輸出Formatted Output 19 | [Further reading延伸閱讀]https://www.python-course.eu/python3_formatted_output.php 20 | 21 | [2]各種資料型態及其運算[1][2][3][4]...[X] 22 | 23 | 數字型(numeric)資料型態及其運算 24 | 字串(string)資料型態及其運算 25 | 列表|串列(list)資料型態及其運算 26 | 辭典|字典(dic)資料型態及其運算 27 | ……………… 28 | 29 | [3]迴圈與選擇 30 | 迴圈::while | for loop |沒有do-while |range|break|continue 31 | 32 | 33 | while 迴圈 34 | [程式開發作業]最大公因數 35 | 36 | -------------------------------- 37 | range 38 | 39 | -------------------------------- 40 | nested loop 巢狀迴圈 41 | [程式開發作業]99乘法表 42 | 43 | 44 | 選擇結構:If |if-else| ..沒有switch 45 | 46 | [4]函式function 47 | 48 | ----------------------------- 49 | [Further reading延伸閱讀] 50 | http://python3-cookbook.readthedocs.io/zh_CN/latest/chapters/p07_functions.html 51 | 52 | 可接受任意數量參數的函數 53 | 只接受關鍵字參數的函數 54 | 給函數參數增加元資訊 55 | 返回多個值的函數 56 | 定義有預設參數的函數 57 | 定義匿名或內聯函數 58 | 匿名函數捕獲變數值 59 | 減少可調用物件的參數個數 60 | 將單方法的類轉換為函數 61 | 帶額外狀態資訊的回呼函數 62 | 內聯回呼函數 63 | 訪問閉包中定義的變數 64 | 65 | ----------------------------- 66 | 遞迴函式 67 | recursive vs iterative(loop) 68 | ----------------------------- 69 | python內建函式: 70 | ---------------------- 71 | 72 | [5]標準函式庫 73 | binascii: 74 | base64::是一種任意二進位到文本字串的編碼方法,常用於在URL、Cookie、網頁中傳輸少量二進位資料 75 | hashlib::提供了常見的雜湊演算法,如MD5,SHA1 76 | 77 | 78 | [6]第三方模組 79 | pycrypto 80 | pycrypto 2.6.1 81 | Cryptographic modules for Python. 82 | 83 | [7]各種類型檔案存取 84 | -------------------------------------------------------------------------------- /Python2018/列表|串列(list)資料型態及其運算: -------------------------------------------------------------------------------- 1 | 列表|串列(list)資料型態及其運算 2 | 3 | python提供內建的list類別 4 | 5 | ================================== 6 | list1 = list() 7 | list1 = [] 8 | 9 | list2 = list([2, 3, 4]) 10 | list2 = [2, 3, 4] 11 | 12 | list3 = list(["red", "green", "blue"]) 13 | list4 = list(range(3, 6)) 14 | list5 = list("abcd") 15 | =================================== 16 | 17 | ------------------------------------------------ 18 | [動手做]下列範例會產生何種結果 19 | list1 = [21, 33, 14, 12, 32,98] 20 | 21 | len(list1) 22 | max(list1) 23 | min(list1) 24 | sum(list1) 25 | ------------------------------------------------ 26 | 串列的加法|乘法與分割運算 27 | 28 | [動手做]下列範例會產生何種結果 29 | list1 = [21, 23, 25] 30 | list2 = [11, 92] 31 | 32 | list3 = list1 + list2 33 | list3 34 | list4 = 3 * list1 35 | list4 36 | list5 = list3[2 : 4] 37 | list5 38 | ------------------------------------------------ 39 | 超強大功能list comprehension 40 | A list comprehension consists of brackets containing an expression followed by a for clause, 41 | then zero or more for or if clauses. 42 | The result will be a new list resulting from evaluating the expression 43 | in the context of the for and if clauses which follow it. 44 | 45 | https://en.wikipedia.org/wiki/List_comprehension 46 | 47 | list1 = [x for x range(0, 5)] # Returns a list of 0, 1, 2, 4 48 | list1 49 | list2 = [0.5 * x for x in list1] 50 | list2 51 | list3 = [x for x in list2 if x < 1.5] 52 | list3 53 | ------------------------------------------------ 54 | 加一元素到串列的尾端:append() 55 | 回傳元素x 出現於串列的次數:count() 56 | 附加在l中所有元素於串列:extend() 57 | 回傳在串列中第一次出現元素x的索引:index() 58 | 將串列中的元素加以反轉:reverse() 59 | 由小至大排序串列中的元素:sort() 60 | 61 | items = "Welcome to the MyFirstCTF".split() 62 | print(items) 63 | 64 | items = "314#123#738#445".split("#") 65 | print(items) 66 | 67 | 68 | 69 | -------------------------------------------------------------------------------- /Python2018/字串(string)資料型態及其運算: -------------------------------------------------------------------------------- 1 | 字串(string)資料型態及其運算 2 | 3 | ===================================== 4 | python提供內建的str字串類別 5 | 字串物件是不可變更的 6 | 字串物件是不可變更的。一旦被建立,其內容就不可以改變。 7 | 為了效率最佳化,若字串內容相同,則Python只使用一物件。 8 | ===================================== 9 | string = "" 10 | stringa = str() 11 | id(string) 12 | id(stringa) 13 | 14 | stringb = str("MyfirstCTF") 15 | 16 | string1 = "I love you" 17 | 18 | ===================================== 19 | str 類別有許多方法(運算子) 20 | ===================================== 21 | len(stringb) 22 | max(stringb) 23 | min(stringb) 24 | --------------------------- 25 | 索引運算子[] 26 | --------------------------- 27 | 28 | --------------------------- 29 | +、 *、 [ : ] 與 in 運算子 30 | --------------------------- 31 | s = '}FTC NOCTIH ot emocleW{noctih' 32 | ''.join(reversed(s)) 33 | 34 | ---------replace()取代-------------- 35 | string1.replace("love","hate") 36 | 37 | ---------join()-------------- 38 | '_'.join("Dragon") 39 | 'x'.join("Dragon") 40 | 41 | -------split()--------------- 42 | string1.split() 43 | 44 | #string2 = 'x'.join("Dragon") 45 | #string2.split(sep='x') 46 | 47 | string1.upper() 48 | string1.swapcase() 49 | 50 | ###有空白==>去除空白############# 51 | string11 = " I love you " 52 | string11.strip() 53 | 54 | 55 | ---擴充版凱薩加密及暴力破解---------------------------------------------------------- 56 | 57 | #!/usr/bin/env python3 58 | 59 | alpha = 'abcdefghijklmnopqrstuvwxyz' 60 | num = '0123456789' 61 | alnum = alpha + num 62 | 63 | ctext = '7sj-ighm-742q3w4t' 64 | 65 | def rotate(s, num): 66 | new1 = '' 67 | for c in s: 68 | if c in alnum: 69 | new1 += alnum[(alnum.index(c) + num) % 36] 70 | else: 71 | new1 += c 72 | return new1 73 | 74 | for x in range(36): 75 | print("{}".format(rotate(ctext, x))) 76 | 77 | 78 | ==================== 79 | #!/usr/bin/env python3 80 | import string 81 | 82 | alphabet = string.ascii_lowercase + string.ascii_uppercase + string.digits 83 | 84 | ctext = "7sj-ighm-742q3w4t" 85 | 86 | def shift(n): 87 | message = "" 88 | for index, char in enumerate(ctext): 89 | if char == "-": 90 | message += char 91 | else: 92 | message += alphabet[(alphabet.index(ctext[index])+n)%len(alphabet)] 93 | return message.upper() 94 | 95 | for i in range(len(alphabet)): 96 | message = shift(i) 97 | if "RC3" in message: 98 | print(message) 99 | 100 | ------------------------------------------------------------------ 101 | a='cvqAeqacLtqazEigwiXobxrCrtuiTzahfFreqc{bnjrKwgk83kgd43j85ePgb_e_rwqr7fvbmHjklo3tews_hmkogooyf0vbnk0ii87Drfgh_n kiwutfb0ghk9ro987k5tfb_hjiouo087ptfcv}' 102 | 103 | a=a[3:] 104 | flag = '' 105 | for x in range(0,len(a),1): 106 | if x%5==0: 107 | flag+=a[x] 108 | print flag 109 | ------------------------------------------------------------------ 110 | 111 | 112 | 113 | re模組與正規表達法(NeXT) 114 | -------------------------------------------------------------------------------- /Python2018/辭典|字典(dic)資料型態及其運算: -------------------------------------------------------------------------------- 1 | 辭典|字典(dic)資料型態及其運算 2 | 3 | dict = {'key1': 'value1', 'key2': value2, 'key3': 'value2'}; 4 | 5 | dict = {'Name': 'Zara', 'Age': 7, 'Class': 'First'}; 6 | 7 | -------------------------------------- 8 | print "dict['Name']: ", dict['Name']; 9 | print "dict['Age']: ", dict['Age']; 10 | 11 | 12 | 13 | 14 | -------------------------------------- 15 | 加密 16 | encrypt = {'明文1': '密文1', '明文2': '密文2', '明文3': '密文3'}; 17 | -------> 18 | 解密 19 | decrypt = {'密文1': '明文1', '密文2': '明文2', '密文3': '明文3'}; 20 | -------> 21 | 22 | -------------------------------------- 23 | 開發你的密碼系統 24 | 限定英文字母 25 | 頭尾互換 26 | -------------------------------------------------------------------------------- /Python_books.md: -------------------------------------------------------------------------------- 1 | # Python Programming 2 | ``` 3 | Python 程式設計入門 (適用於 2.x 與 3.x 版) 葉難/博碩出版日期:2015-04-01 4 | 5 | Python 3.5 技術手冊 林信良/碁峰出版日期:2016-07-28 6 | ``` 7 | ``` 8 | Python 程式設計入門指南 Y. Daniel Liang 著、蔡明志 譯/碁峰出版日期:2016-06-29 9 | 10 | C++ 程式設計導論, 3/e (Introduction to Programming with C++, 3/e) 11 | Y. Daniel Liang 著、蔡明志 譯/碁峰出版日期:2014-07-28 12 | 13 | Java 程式設計導論(第十版) (Introduction to Java Programming : Comprehensive Version, 10/e) 14 | Y. Daniel Liang 著、蔡明志 譯/碁峰出版日期:2015-04-14 15 | ``` 16 | ``` 17 | Python 也可以這樣學 董付國 著、廖信彥 審校/博碩出版日期:2017-10-30 18 | 19 | Python 入門邁向高手之路王者歸來 洪錦魁/上奇資訊出版日期:2017-12-15 20 | 21 | Python 程式設計入門:金融商管實務案例, 2/e 林萍珍/博碩出版日期:2017-05-07 22 | ``` 23 | ``` 24 | 精通 Python 3 程式設計 (Programming in Python 3: A Complete Introduction to the Python Language, 2/e) 25 | 繁體中文/Mark Summerfield 著、蔣大偉 譯/碁峰出版日期:2010-11-24 26 | ``` 27 | ``` 28 | Python 錦囊妙計, 3/e (Python Cookbook, 3/e) 29 | 繁體中文/David Beazley, Brian K. Jones 著、黃銘偉 譯/歐萊禮出版日期:2014-04-14 30 | ``` 31 | ``` 32 | Python 技術手冊, 3/e (Python in a Nutshell: A Desktop Quick Reference, 3/e) 33 | 繁體中文/Alex Martelli 著、黃銘偉 譯/歐萊禮出版日期:2018-01-12 34 | ``` 35 | # Python 標準函式庫 36 | ``` 37 | Python 函式庫語法範例字典 38 | 繁體中文/池内孝啓, 鈴木たかのり, 石本敦夫, 小坂健二郎, 真嘉比愛 著、林子政 譯/旗標出版日期:2016-08-25 39 | ``` 40 | 41 | ``` 42 | The Python Standard Library by Example (Paperback) 43 | Doug Hellmann/Addison-Wesley Professional出版日期:2011-06-11 44 | ``` 45 | 46 | # Python Network Programming 網路程式開發 47 | ``` 48 | Foundations of Python Network Programming, 3/e (Paperback) 49 | Brandon Rhodes, John Goerzen/Apress出版日期:2014-10-20 50 | ``` 51 | ``` 52 | Mastering Python Networking 53 | Eric Chou/Packt Publishing 出版日期:2017-06-28 54 | ``` 55 | 56 | ``` 57 | Python Network Programming Cookbook Second Edition 58 | Pradeeban Kathiravelu, Dr. M. O. Faruque Sarker/Packt Publishing 出版日期:2017-08-09 59 | ``` 60 | ``` 61 | Complex Network Analysis in Python: Recognize - Construct - Visualize - Analyze - Interpret 62 | Dmitry Zinoviev/Pragmatic Bookshelf出版日期:2018-01-29 63 | ``` 64 | 65 | # Python Web 網站程式開發 66 | ``` 67 | 一次搞定:所有Python Web框架開發百科全書(最完整Python Web框架,包括Django、Flask、Tornado、Twisted等) 68 | 繁體中文/劉長龍/佳魁資訊出版日期:2017-03-27 69 | ``` 70 | ``` 71 | Python Web開發實戰 簡體中文/董偉明/電子工業出版社出版日期:2016-09-01 72 | 一舉兩得功力大精進:學 Python+Web 賺一個未來 繁體中文/董偉明/佳魁資訊出版日期:2017-01-18 73 | ``` 74 | ``` 75 | It's Django -- 用 Python 迅速打造 Web 應用 76 | 繁體中文/袁克倫、楊孟穎/碁峰出版日期:2015-06-08 77 | ``` 78 | 79 | ``` 80 | Python 架站特訓班 -- Django 最強實戰 81 | 繁體中文/鄧文淵 總監製/文淵閣工作室 編著/碁峰出版日期:2017-08-29 82 | ``` 83 | 84 | 85 | # Python Web manipulation 網站存取 86 | ``` 87 | 網站擷取|使用Python (Web Scraping with Python: Collecting Data from the Modern Web) 88 | Ryan Mitchell 著,Studio Tib 譯/歐萊禮出版日期:2016-10-02 89 | ``` 90 | ``` 91 | 用 Python 寫網絡爬蟲 (Web Scraping with Python) 92 | 簡體中文/[澳]理乍得 勞森/人民郵電出版社出版日期:2016-08-01 93 | ``` 94 | ``` 95 | Python 網絡爬蟲實戰 96 | 簡體中文/胡松濤/清華大學出版社出版日期:2017-01-01 97 | ``` 98 | 99 | ``` 100 | Python 爬蟲開發與項目實戰 101 | 簡體中文/範傳輝/機械工業出版社出版日期:2017-06-01 102 | ``` 103 | # Python and IOT 104 | ``` 105 | Raspberry Pi Python 編程入門 106 | 簡體中文/Simon Monk/科學出版社出版日期:2014-02-01 107 | ``` 108 | ``` 109 | Python Programming with Raspberry Pi 110 | Sai Yamanoor, Srihari Yamanoor/Packt Publishing - ebooks Account出版日期:2017-04-28 111 | ``` 112 | ``` 113 | Raspberry Pi for Python Programmers Cookbook - Second Edition 114 | 英文/Tim Cox/Packt Publishing - ebooks Account出版日期:2016-10-07 115 | ``` 116 | ``` 117 | Raspberry Pi 3 Cookbook for Python Programmers - Third Edition: 118 | Over 70 recipes for Python Programmers to unleash the potential of Raspberry Pi 3 119 | 英文/Tim Cox, Dr. Steven Lawrence Fernandes/Packt Publishing 出版日期:2018-04-30 120 | ``` 121 | ``` 122 | Raspberry Pi Image Processing Programming: 123 | Develop Real-Life Examples with Python, Pillow, and SciPy 124 | 英文/Ashwin Pajankar/Apress出版日期:2017-03-24 125 | ``` 126 | ``` 127 | Raspberry Pi機器人製作實例:用Python Linux和傳感器搭建智慧小車 128 | 簡體中文/多納特 (Wolfram Donat)/人民郵電出版社出版日期:2016-03-01 129 | ``` 130 | 131 | ``` 132 | Python x Arduino 物聯網整合開發實戰 133 | 繁體中文/Pratik Desai 著、CAVEDU團隊 曾吉弘 譯/碁峰出版日期:2016-06-29 134 | ``` 135 | # Python and Blockchain 136 | 137 | 138 | # Python and Finance 139 | ``` 140 | Python 網頁程式交易 APP 實作:Web + MySQL + Django 141 | 林萍珍/博碩文化出版日期:2018-03-12 142 | ``` 143 | ``` 144 | Python:期貨演算法交易實務 121個關鍵技巧詳解 145 | 酆士昌、劉承彥 著/博碩出版日期:2017-11-16 146 | ``` 147 | ``` 148 | Python金融實戰 ( Python for Finance ) 149 | 簡體中文/嚴玉星/人民郵電出版社出版日期:2017-07-01 150 | ``` 151 | ``` 152 | 金融科技實戰:Python與量化投資 153 | 蔡立耑/博碩出版日期:2018-01-04 154 | 介紹隨機變數、描述性統計、變異數分析、推論統計、迴歸分析等統計學基礎。 155 | 說明資產投資組合理論、收益率及風險、資本資產定價模型、三因子模型等金融理論。 156 | 認識時間序列的基本概念、性質和預測、GARCH模型、配對交易策略。 157 | 解說投資相關的K線圖、RSI相對強弱指標、動量交易策略、均線系統策略 158 | ``` 159 | ``` 160 | Python與量化投資:從基礎到實戰 161 | 簡體中文/王小川, 等/電子工業出版社出版日期:2018-03-01 162 | ``` 163 | 164 | # Python and security 165 | ``` 166 | 黑帽 Python | 給駭客與滲透測試者的 Python 開發指南 167 | Justin Seitz 著、Studio Tib. 譯/碁峰出版日期:2015-10-13 168 | 169 | Black Hat Python: Python Programming for Hackers and Pentesters (Paperback) 170 | Justin Seitz/No Starch Press出版日期:2014-12-21 171 | ``` 172 | ``` 173 | Python絕技:運用Python成為頂級駭客 174 | Violent Python : A Cookbook for Hacker, Forensic Analysis, Penetration Testers and Security Engineers 175 | 簡體中文/奧科羅 (TJ O'Connor)/電子工業出版社出版日期:2016-01-01 176 | ``` 177 | ``` 178 | Understanding Network Hacks: Attack and Defense with Python 179 | Bastian Ballmann/Springer出版日期:2015-01-20 180 | ``` 181 | 182 | # Python Data Science 183 | ``` 184 | Python 資料運算與分析實戰:一次搞懂 NumPy•SciPy•Matplotlib•pandas 最強套件 185 | 作者: 中久喜健司 譯者: 莊永裕 出版社:旗標   出版日期:2018/02/05 186 | ``` 187 | ``` 188 | 高效率資料分析|使用Python (Foundations for Analytics with Python) 189 | Clinton W. Brownley 著、賴屹民 譯/歐萊禮出版日期:2016-12-19 190 | ``` 191 | 192 | ``` 193 | R 語言使用者的 Python 學習筆記 194 | https://github.com/yaojenkuo/learn_python_for_a_r_user 195 | ``` 196 | ``` 197 | Python 資料分析 (Python Data Analysis) 198 | 簡體中文/[印尼]Ivan Idris 伊德裡斯/人民郵電出版社出版日期:2016-02-01 199 | ``` 200 | ``` 201 | Python3 for Data Science 202 | https://www.udemy.com/python-for-data-science/?couponCode=PYTHON-DATA-SCI10 203 | https://github.com/udemy-course/python-data-science-intro 204 | 線上學習程式碼 205 | http://nbviewer.jupyter.org/github/udemy-course/python-data-science-intro/tree/master/ 206 | ``` 207 | # Python BigData analysis 208 | ``` 209 | Python+Spark 2.0+Hadoop 機器學習與大數據分析實戰 210 | 繁體中文/林大貴/博碩出版日期:2016-10-03 211 | ``` 212 | 213 | # Python Machine learning 214 | ``` 215 | Python 機器學習 (Python Machine Learning) 216 | Sebastian Raschka 著,劉立民、吳建華 譯/博碩出版日期:2016-09-14 217 | 218 | https://github.com/rasbt/python-machine-learning-book-2nd-edition#whats-new-in-the-second-edition-from-the-first-edition 219 | https://github.com/rasbt/python-machine-learning-book 220 | ``` 221 | ``` 222 | 初探機器學習|使用 Python (Thoughtful Machine Learning with Python) 223 | Matthew Kirk 著;陳仁和 譯/歐萊禮出版日期:2017-09-14 224 | ``` 225 | ``` 226 | 精通機器學習|使用Python (Introduction to Machine Learning with Python: A Guide for Data Scientists) 227 | Sarah Guido, Andreas C. Mueller 著、李宜修 譯/歐萊禮出版日期:2017-10-31 228 | ``` 229 | ``` 230 | 機器學習 | 使用 Python 進行預測分析的基本技術 231 | 繁體中文/Michael Bowles 著,賴屹民 譯/碁峰出版日期:2016-09-12 232 | ``` 233 | ``` 234 | 機器學習:Python實踐 235 | 簡體中文/魏貞原/電子工業出版社出版日期:2018-01-01 236 | ``` 237 | 238 | ``` 239 | Python 機器學習實踐指南 (Python Machine Learning Blueprints) 240 | 簡體中文/庫姆斯 (Alexander T.Combs)/人民郵電出版社出版日期:2017-05-01 241 | ``` 242 | 243 | ``` 244 | Python 數據挖掘入門與實踐 (Learning Data Mining with Python) 245 | 簡體中文/羅伯特·萊頓 (Robert Layton)/人民郵電出版社出版日期:2016-07-01 246 | ``` 247 | 248 | # Python Deep learning深度學習 249 | ``` 250 | Deep Learning:用Python進行深度學習的基礎理論實作 251 | https://github.com/oreilly-japan/deep-learning-from-scratch 252 | 作者: 斎藤康毅 譯者: 吳嘉芳 253 | 出版社:歐萊禮 出版日期:2017/08/17 254 | 第一章 Python入門 第二章 感知器 255 | 第三章 神經網路 第四章 神經網路的學習 第五章 誤差反向傳播法 256 | 第六章 與學習有關的技巧 第七章 卷積神經網路 第八章 深度學習 257 | 附錄A Softmax-with-Loss層的計算圖 258 | ``` 259 | ``` 260 | Python 深度學習 (Python Deep Learning) 261 | Valentino Zocca, Gianmario Spacagna, Daniel Slater, Peter Roelants 著 262 | 劉立民、吳建華、陳開煇 譯/博碩出版日期:2018-01-04 263 | ``` 264 | # Python/TensorFlow Deep learning深度學習 265 | ``` 266 | 深度學習快速入門—使用 TensorFlow (Getting started with TensorFlow) Giancarlo Zaccone/博碩出版日期:2017-01-10 267 | Getting Started with TensorFlow (Paperback) /Giancarlo Zaccone/Packt Publishing 出版日期:2016-07-29 268 | ``` 269 | ``` 270 | Deep Learning with TensorFlow - Second Edition: Explore neural networks with Python 271 | Giancarlo Zaccone, Md. Rezaul Karim/Packt Publishing 出版日期:2018-04-10 272 | ``` 273 | ``` 274 | 21個項目玩轉深度學習——基於TensorFlow的實踐詳解 275 | 簡體中文/何之源/電子工業出版社出版日期:2018-03-01 276 | ``` 277 | ``` 278 | TensorFlow+Keras 深度學習人工智慧實務應用 279 | 繁體中文/林大貴 著/博碩出版日期:2017-06-08 280 | ``` 281 | # Python/PyTorch Deep learning深度學習 282 | ``` 283 | 深度學習入門之PyTorch 284 | 簡體中文/廖星宇/電子工業出版社出版日期:2017-09-01 285 | ``` 286 | ``` 287 | 深度學習框架PyTorch:入門與實踐 288 | 簡體中文/陳雲/電子工業出版社出版日期:2018-01-01 289 | ``` 290 | ``` 291 | 深度學習之PyTorch實戰電腦視覺 292 | 簡體中文/唐進民/電子工業出版社出版日期:2018-05-01 293 | ``` 294 | ``` 295 | Deep Learning with PyTorch: A practical approach to building neural network models using PyTorch 296 | Vishnu Subramanian/Packt Publishing出版日期:2018-02-23 297 | ``` 298 | 299 | # Python reinforcement learning強化學習 300 | ``` 301 | Practical Reinforcement Learning ==> OpenAI Gym, Python 302 | Dr. Engr. S.M. Farrukh Akhtar/Packt Publishing 出版日期:2017-10-20 303 | ``` 304 | ``` 305 | Reinforcement Learning: With Open AI, TensorFlow and Keras Using Python 306 | Abhishek Nandy, Manisha Biswas/Apress出版日期:2017-12-08 307 | ``` 308 | ``` 309 | Reinforcement Learning with Tensorflow: 310 | Learn the art of designing self-learning systems with TensorFlow and OpenAI Gym 311 | Sayon Dutta/Packt Publishing 出版日期:2018-05-09 312 | ``` 313 | 314 | 315 | 316 | 317 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python 2 | 3 | 4 | ``` 5 | 為什麼要學Python? 6 | 如何學Python?打造你的學習地圖! 7 | Python 3和Python 2的主要差異 8 | ``` 9 | # Python開發環境 10 | 11 | ### Python開發環境@windwos 12 | ``` 13 | 下載python 14 | 安裝Python2.7==>裝在D:\python2 15 | 安裝Python3.6==>裝在D:\python3{記得改成python3} 16 | 17 | [1]使用python interactive shell 18 | 進入python 19 | 在cmd輸入python==>進入 20 | 離開==>exit() 21 | 22 | [2]使用notepad++寫程式==>記得檔名要XXX.py 23 | 執行: 24 | [1]進入你的程式目錄 D:\p3code (三年級) D:\p_code(一(年級) 25 | [2]D:\python2\python.exe XXX.py 26 | 或 D:\python3\python.exe XXX.py 27 | 28 | C:\p3code>path=c:\python3;%path% 29 | C:\p3code>python hello.py 30 | ``` 31 | 32 | ### Python開發環境@Ubuntu 16.04 LTS 64-bit 33 | 34 | ### 使用虛擬開發環境 35 | >* virtualenv 36 | >* 使用Vagrant的虛擬開發環境 37 | 38 | ### 使用IDE 39 | >* 40 | >* 41 | 42 | # [1]輸入與輸出 USER INPUTS AND OUTPUTS: 43 | ``` 44 | 45 | [1.1]輸入:input | Raw_input 46 | raw_input([prompt]) 函數從標準輸入讀取一個行,並返回一個字串(去掉結尾的分行符號) 47 | input([prompt]) 函數和 raw_input([prompt]) 函數基本類似,但是 input 可以接收一個Python運算式作為輸入,並將運算結果返回。 48 | 49 | 從控制台讀取輸入資訊 50 | 51 | [1.2]輸出:print 52 | 53 | [1.3]格式化輸出Formatted Output 54 | ``` 55 | 56 | # [2]各種資料型態(data type)及其運算[1][2][3][4]...[X] 57 | ``` 58 | 識別字與關鍵字 59 | 60 | 數字型(numeric)資料型態及其運算 61 | Integral 類型:整數類型|布爾型 62 | 浮點類型:浮點數|複數 63 | 二進位八進位十進位十六進位數字 64 | 65 | 字串(string)資料型態及其運算 66 | 如何操縱Unicode字串 67 | 68 | Collection Data Types組合類型資料型態 69 | 列表|串列(list)資料型態及其運算 70 | 元組(tuple)資料型態及其運算 71 | 辭典|字典(dic)資料型態及其運算 72 | 集合(set)資料型態及其運算 73 | ``` 74 | ### 運算子: 75 | >* Arithmetic Operators 76 | >* 餘數運算子 (remainder|modulo) 77 | >* Membership Operator 78 | >* Comparison Operators 79 | Logical Operators 80 | 81 | ### 組合類型資料型態的高級特性:切片|迭代 |列表生成式 |生成器|迭代器 82 | 83 | # [3]迴圈與選擇(判斷) 84 | ``` 85 | 迴圈::while | for loop |沒有do-while |range|break|continue 86 | 選擇:If |if-else| ..沒有switch 87 | range break continue 88 | 89 | [3.1]選擇:If |if-else| ..沒有switch 90 | 91 | #猜數字游戲_版本一 92 | 93 | 西元年代對應到的十二生肖 94 | 95 | [3.3]while 迴圈 96 | 97 | #猜數字游戲_版本二:Python3 98 | 99 | [程式開發作業]最大公因數 100 | 101 | 102 | [3.3]range 103 | range(start, stop[, step]) 104 | ``` 105 | 106 | # [4]函式/函數/function 107 | 108 | #### function開發(功能) 109 | 110 | ``` 111 | 可接受任意數量參數的函數 112 | 只接受關鍵字參數的函數 113 | 給函數參數增加元資訊 114 | 返回多個值的函數 115 | 定義有預設參數的函數 116 | 定義匿名或內聯函數 117 | 匿名函數捕獲變數值 118 | 減少可調用物件的參數個數 119 | 將單方法的類轉換為函數 120 | 帶額外狀態資訊的回呼函數 121 | 內聯回呼函數 122 | 訪問閉包中定義的變數 123 | ``` 124 | #### 遞迴函式 125 | 126 | # [5]異常,例外處理與斷言 Exception Handling 127 | 128 | # [6]各種類型檔案存取技術 129 | 130 | #### 文字檔案存取技術 131 | 132 | #### CSV檔案存取技術 133 | 134 | #### 圖片檔案存取技術 135 | 136 | # [7]各種類型資料庫存取技術 137 | 138 | #### MYSQL資料庫存取技術 139 | 140 | #### Postgresql資料庫存取技術 141 | 142 | #### Mongodb資料庫存取技術 143 | 144 | #### Redis資料庫存取技術 145 | 146 | 147 | 148 | -------------------------------------------------------------------------------- /STL/OS模組使用範例: -------------------------------------------------------------------------------- 1 | os模組 2 | This module provides a portable way of using operating system dependent functionality. 3 | 這個模組提供了一種方便的使用作業系統函數的方法。 4 | 5 | ============================================ 6 | os 常用方法 7 | os.remove() 刪除檔 8 | os.rename() 重命名檔 9 | os.walk() 生成目錄樹下的所有檔案名 10 | os.chdir() 改變目錄 11 | os.mkdir/makedirs 創建目錄/多層目錄 12 | os.rmdir/removedirs 刪除目錄/多層目錄 13 | os.listdir() 列出指定目錄的檔 14 | os.getcwd() 取得當前工作目錄 15 | os.chmod() 改變目錄許可權 16 | os.path.basename() 去掉目錄路徑,返回檔案名 17 | os.path.dirname() 去掉檔案名,返回目錄路徑 18 | os.path.join() 將分離的各部分組合成一個路徑名 19 | os.path.split() 返回( dirname(), basename())元組 20 | os.path.splitext() 返回 (filename, extension) 元組 21 | os.path.getatime\ctime\mtime 分別返回最近訪問、創建、修改時間 22 | os.path.getsize() 返回文件大小 23 | os.path.exists() 是否存在 24 | os.path.isabs() 是否為絕對路徑 25 | os.path.isdir() 是否為目錄 26 | os.path.isfile() 是否為檔 27 | ============================================ 28 | -------------------------------------------------------------------------------- /STL/sys模組使用範例: -------------------------------------------------------------------------------- 1 | sys模組用途: 2 | 這個模組可供訪問由解譯器使用或維護的變數和與解譯器進行交互的函數。 3 | This module provides access to some variables used or maintained by the interpreter and 4 | to functions that interact strongly with the interpreter. 5 | It is always available. 6 | 7 | ====================================================================== 8 | Python2 9 | 28.1. sys — System-specific parameters and functions 10 | https://docs.python.org/2/library/sys.html 11 | 12 | Python3 13 | 29.1. sys — System-specific parameters and functions 14 | https://docs.python.org/3/library/sys.html 15 | ====================================================================== 16 | [動手做]下列範例會產生何種結果 17 | 18 | import sys 19 | 20 | sys.modules # This is a dictionary that maps module names to modules which have already been loaded. 21 | 22 | sys.path # A list of strings that specifies the search path for modules. 23 | 24 | sys.platform # 來判斷是否要執行平台相關的程式碼 25 | 26 | sys.version_info # 提供一組 tuple (major, minor, micro, releaselevel, serial) 來表示當前 Python 的版本。 27 | 28 | sys.builtin_module_names # A tuple of strings giving the names of all modules that are compiled into this Python interpreter. 29 | 30 | sys.version # A string containing the version number of the Python interpreter plus additional information 31 | 32 | print sys.argv 33 | 34 | 35 | sys.argv 命令列參數List,第一個元素是程式本身路徑 36 | sys.modules.keys() 返回所有已經導入的模組清單 37 | sys.exc_info() 獲取當前正在處理的異常類,exc_type、exc_value、exc_traceback當前處理的異常詳細資訊 38 | sys.exit(n) 退出程式,正常退出時exit(0) 39 | sys.hexversion 獲取Python解釋程式的版本值,16進制格式如:0x020403F0 40 | sys.version 獲取Python解釋程式的版本資訊 41 | sys.maxint 最大的Int值 42 | sys.maxunicode 最大的Unicode值 43 | sys.modules 返回系統導入的模組欄位,key是模組名,value是模組 44 | sys.path 返回模組的搜索路徑,初始化時使用PYTHONPATH環境變數的值 45 | sys.platform 返回作業系統平臺名稱 46 | sys.stdout 標準輸出 47 | sys.stdin 標準輸入 48 | sys.stderr 錯誤輸出 49 | sys.exc_clear() 用來清除當前執行緒所出現的當前的或最近的錯誤資訊 50 | sys.exec_prefix 返回平臺獨立的python檔安裝的位置 51 | sys.byteorder 本地位元組規則的指示器,big-endian平臺的值是'big',little-endian平臺的值是'little' 52 | sys.copyright 記錄python版權相關的東西 53 | sys.api_version 解譯器的C的API版本 54 | 55 | ====================================================================== 56 | sys.argv[]是python獲取命令列參數的方法 57 | 58 | 在terminal中會輸入的指令 ls -a 59 | -a就是命令列參數 60 | sys.argv[0] 代表了文件的檔案名稱本身,意思就是ls 61 | sys.argv[1] 就代表了-a 62 | 63 | ls -help 64 | ls -al 65 | ls -version 66 | ====================================================================== 67 | # -*- coding: utf-8 -*- 68 | 69 | import sys 70 | 71 | #建立一個讀取檔案的function能將檔案內容print出來 72 | 73 | def readfile(filename): 74 | 75 | '''read file and print''' 76 | 77 | f = file(filename) 78 | 79 | while True: 80 | 81 | line = f.readline() 82 | 83 | if len(line) == 0: 84 | 85 | break 86 | 87 | print line, 88 | 89 | f.close() 90 | 91 | 92 | 93 | #開始對sys.argv下定義 94 | 95 | if len(sys.argv) < 2: #len小於2也就是不帶參數啦 96 | 97 | print 'no argument' 98 | 99 | sys.exit() 100 | 101 | if sys.argv[1].startswith('--'): 102 | 103 | option = sys.argv[1][2:] # 取出sys.argv[1]的數值但是忽略掉'--'這兩個字元 104 | 105 | if option == 'version': 106 | 107 | print 'Version 1.2.3' 108 | 109 | elif option == 'help': 110 | 111 | print 'help documention' 112 | 113 | else: 114 | 115 | print 'only --version --help can be used' 116 | 117 | sys.exit() 118 | 119 | else: 120 | 121 | for filename in sys.argv[1:]: #檔案名稱於參數位置時讀取檔案 122 | 123 | readfile(filename) 124 | 125 | 126 | """ 127 | 128 | 此檔案名稱為readfile.py 129 | 130 | 則可以用readfile.py --version來查詢版號 131 | 132 | readfile.py --help來查詢help文件 133 | 134 | readfile.py readme.txt 可以執行function 135 | ====================================================================== 136 | #!/usr/bin/python 137 | # -*- coding: UTF-8 -*- 138 | import sys 139 | 140 | # Check number of strings passed 141 | if len(sys.argv) != 4: 142 | print("Usage: python Calculator.py operand1 operator operand2") 143 | sys.exit() 144 | 145 | # Determine the operator 146 | if sys.argv[2][0] == '+': 147 | result = eval(sys.argv[1]) + eval(sys.argv[3]) 148 | elif sys.argv[2][0] == '-': 149 | result = eval(sys.argv[1]) - eval(sys.argv[3]) 150 | elif sys.argv[2][0] == '*': 151 | result = eval(sys.argv[1]) * eval(sys.argv[3]) 152 | elif sys.argv[2][0] == '/': 153 | result = eval(sys.argv[1]) / eval(sys.argv[3]) 154 | 155 | # Display result 156 | print(sys.argv[1], sys.argv[2], sys.argv[3], "=", result) 157 | ====================================================================== 158 | -------------------------------------------------------------------------------- /code_day1/Calculator.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | import sys 4 | 5 | # Check number of strings passed 6 | if len(sys.argv) != 4: 7 | print("Usage: python Calculator.py operand1 operator operand2") 8 | sys.exit() 9 | 10 | # Determine the operator 11 | if sys.argv[2][0] == '+': 12 | result = eval(sys.argv[1]) + eval(sys.argv[3]) 13 | elif sys.argv[2][0] == '-': 14 | result = eval(sys.argv[1]) - eval(sys.argv[3]) 15 | elif sys.argv[2][0] == '*': 16 | result = eval(sys.argv[1]) * eval(sys.argv[3]) 17 | elif sys.argv[2][0] == '/': 18 | result = eval(sys.argv[1]) / eval(sys.argv[3]) 19 | 20 | # Display result 21 | print(sys.argv[1], sys.argv[2], sys.argv[3], "=", result) 22 | -------------------------------------------------------------------------------- /code_day1/if_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | 4 | number = 2315698 5 | 6 | guess = int(raw_input('Enter an integer : ')) 7 | 8 | if guess == number: 9 | print 'Congratulations, you guessed it.' # New block starts here 10 | print "(This is flag: BreakALL{It is easy to write if statement}!)" # New block ends here 11 | elif guess < number: 12 | print 'No, it is a little higher than that' 13 | # You can do whatever you want in a block ... 14 | else: 15 | print 'No, it is a little lower than that' 16 | # you must have guess > number to reach here 17 | 18 | print 'Done' 19 | 20 | # This last statement is always executed, after the if statement is executed -------------------------------------------------------------------------------- /code_day1/my_XOR.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | 4 | def crypt(source, key): 5 | from itertools import cycle 6 | result = '' 7 | temp = cycle(key) 8 | for ch in source: 9 | result = result + chr(ord(ch) ^ ord(next(temp))) 10 | return result 11 | 12 | source = 'BreakALLCTF_IknowhowtoXORRRRing' 13 | key = 'HappyHackingHigh' 14 | 15 | print('未加密的明文:'+source) 16 | encrypted = crypt(source, key) 17 | print('加密過的密文:'+encrypted) 18 | decrypted = crypt(encrypted, key) 19 | print('解密過的答案:'+decrypted) 20 | print('使用的金鑰:'+ key) -------------------------------------------------------------------------------- /code_day1/new.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | 4 | if __name__ == '__main__': 5 | fp = open('test.txt','w') 6 | string = raw_input('please input a string:\n') 7 | string = string.upper() 8 | fp.write(string) 9 | fp = open('test.txt','r') 10 | print fp.read() 11 | fp.close() -------------------------------------------------------------------------------- /code_day1/new2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | #coding=utf-8 3 | 4 | from __future__ import print_function 5 | 6 | import random 7 | 8 | x = random.randint(1,100) 9 | 10 | while (1): 11 | number = int(input("猜數字,輸入一個數字:")) 12 | if x == number: 13 | print("您猜對了!") 14 | print("獎品是 BreakALL{you have done a good guess}") 15 | break 16 | elif x > number: 17 | print("比",number,"大") 18 | elif x < number: 19 | print("比",number,"小") 20 | -------------------------------------------------------------------------------- /code_day1/readme: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /code_day1/sys_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: UTF-8 -*- 3 | import sys 4 | 5 | PY2 = sys.version_info.major == 2 6 | PY3 = sys.version_info.major == 3 --------------------------------------------------------------------------------