Cov txheej txheem:
- Kauj Ruam 1: Sau Cov Ntaub Ntawv Teeb
- Kauj ruam 2: Cov Ntaub Ntawv Encryption/decryption
- Kauj Ruam 3: Kev Ua Haujlwm ntawm Cov Ntaub Ntawv
Video: Nab hab sej Kev Ruaj Ntseg Kev Ruaj Ntseg/Kev Txiav Txim Siab Software: 3 Kauj Ruam
2024 Tus sau: John Day | [email protected]. Kawg hloov kho: 2024-01-30 09:27
Hauv Cov Lus Qhia Kuv yuav qhia koj li cas nrog qee qhov Python yooj yim, koj tuaj yeem khaws koj cov ntaub ntawv ruaj ntseg siv kev lag luam tus qauv AES.
Yuav tsum:
Nab hab sej 3.7
PyAesCrypt tsev qiv ntawv
- hashlib library
Yog tias koj tsis muaj cov tsev qiv ntawv no, koj tuaj yeem teeb tsa tau yooj yim los ntawm kev ntaus:
pip3 install hashlib
pip3 nruab PyAesCrypt
hauv lub davhlau ya nyob twg (lossis CMD)
Koj yuav tsum muaj cov no:
- random tsev qiv ntawv
- os lib
- lub tsev qiv ntawv
Kuv tab tom siv OS X, tab sis nws yuav tsum tsis muaj teeb meem ntau dhau, tshwj tsis yog rau cov lus qhia ntawm qhov sib tsoo hauv cov kab ntawv (OS X: /, Windows:)
Thov nco tseg: Vim tias muaj qee qhov tsis sib xws, qhov tsis txaus ntseeg hauv txoj cai tsis qhia rau qee yam. Yog li yuav tsis muaj qhov nkag rau hauv cov kab lus tso tawm, txawm li cas los xij lawv muaj nyob hauv Python cov ntaub ntawv kuv tau txuas nrog qhov kawg, thiab hauv cov duab uas tau muab tso rau. Tsuas yog tsis txhob coj tus lej ncaj qha los ntawm cov ntawv pom, vim nws yuav tsis ua haujlwm vim tsis muaj qhov nkag mus
Yog tias koj muaj txhua qhov kev cia siab tau teeb tsa, cia peb txav mus rau Kauj Ruam 1.
Kauj Ruam 1: Sau Cov Ntaub Ntawv Teeb
Ib qho ntawm cov xwm txheej uas ua rau kom muaj kev nyab xeeb yog kev siv hashes los tshuaj xyuas tus password. Cov ntaub ntawv teeb tsa (Kuv hu kuv li setupsafe.py) yog:
- Tsim cov ntawv tais ceev tseg thiab cov ntaub ntawv dag rau tus password
- Teeb tus password
- Teev tus lej naj npawb
- Hash tus password
Ua ntej tshaj, peb tab tom yuav ntshuam peb cov kev cia siab:
los ntawm sys ntshuam *
import os
ntshuam ntshuam
import hashlib
Tom ntej no peb yuav tsim cov ntawv tais ceev tseg rau lub tsev tus password hash thiab cov ntaub ntawv dummy:
sim: yog tias tsis os.path.exists ('desktop/safesetup'):
os.mkdir ('desktop/safesetup/')
tsuas yog OSError:
print ("Yuam kev tsim nplaub tshev")
Txoj cai no yuav tsim daim nplaub tshev hu ua safesetup (tshwj tsis yog nws twb muaj lawm).
Tom qab qhov no, peb yuav teeb tus password, thiab tsim tus lej tsis sib xws ntawm 1 txog 100 raws li peb txoj hauv kev mus rau cov ntaub ntawv dummy:
thoob ntiaj teb tus passwordpassword = argv [1].encode ('utf-8')
n = random.randint (1, 101)
Tam sim no peb muaj peb tus password thiab peb tus lej cov ntaub ntawv, peb tab tom tsim 99 cov ntaub ntawv dummy hauv kev ruaj ntseg, thiab ib daim ntawv tiag uas yuav muaj peb tus lej hash:
rau x hauv kab (101): yog (x! = n):
f = qhib (("desktop/safesetup/"+str (x)), "w+")
f.close ()
lwm tus:
password = hashlib.sha256 (password).hexdigest ()
f = qhib (("desktop/safesetup/"+str (x)), "w+")
f.write (password)
f.close ()
luam tawm (n)
Cov ntaub ntawv tiag tiag hu ua xijpeem integer n yog. Cov ntaub ntawv no muaj peb tus lej zais, tom qab tau siv lub sha256 algorithm (qhov hash algorithm tau siv dav hauv cryptocurrencies, tshwj xeeb tshaj yog Bitcoin).
Nco ntsoov tias n yog dab tsi (nws yuav luam tawm hauv lub console), vim nws tseem ceeb npaum li tus password.
Qhov ntawd yog txhua yam peb xav tau rau peb cov phiaj xwm teeb tsa, yog li tam sim no peb yuav txav mus rau qhov kev pabcuam encryption/decryption.
Kauj ruam 2: Cov Ntaub Ntawv Encryption/decryption
Kev teeb tsa ntu ntawm cov ntaub ntawv tseem ceeb ntshuam qhov kev cia siab, hashes tus lej nkag nkag, thiab khaws tus lej tiag tiag hash siv cov ntaub ntawv nkag mus.
Ua ntej, kev vam khom:
los ntawm sys ntshuam *ntshuam os
ntshuam pyAesCrypt
import hashlib
Tom ntej no, qhov hashing ntawm tus nkag lo lus zais:
password = argv [1].encode ('utf-8') password = hashlib.sha256 (password).hexdigest ()
Thaum kawg, tus hashed retrieval password:
file_key = str (argv [2]) hash = qhib (("desktop/safesetup/" + file_key), ("r +")). nyeem ()
Ntu ob ntawm cov ntaub ntawv encryption sib piv cov hashes, txiav txim siab qhov tseeb ntawm kev sib piv, thiab siv AESCrypt nab hab sej lub tsev qiv ntawv los encrypt lossis decrypt koj cov ntaub ntawv xaiv. Nov yog qhov loj me me ntawm cov cai, tab sis kuv yuav rhuav nws:
yog (lo lus zais == hash): luam tawm ("Tus lej lees paub")
bufferSize = 64 * 1024
ua haujlwm = str (cov tswv yim ("Puas yog koj tab tom nrhiav lossis zais cov ntaub ntawv? (r lossis e)"))
yog (ua haujlwm == 'r'):
file_name = str (cov tswv yim ("Cov ntaub ntawv mus muab tau:"))
pyAesCrypt.decryptFile ((file_name + ".aes"), file_name, password, bufferSize
os.remove ((file_name + ".aes"))
elif (kev ua haujlwm == 'e'):
file_name = str (input ("Cov ntaub ntawv rau encrypt:"))
pyAesCrypt.encryptFile (file_name, (file_name + ".aes"), password, bufferSize
os.remove (file_name)
lwm tus:
print ("Yuam kev: Cov ntaub ntawv tsis raug")
lwm tus:
print ("Kev tsis lees paub")
Thawj qhov yog cov lus txiav txim siab seb qhov hashed passwords zoo li cas. Yog tias lawv ua, nws tseem mus nug seb koj puas xav encrypt cov ntaub ntawv lossis khaws cov ntaub ntawv encrypted. Nyob ntawm koj lub tswv yim, nws yuav yog encrypt lossis decrypt cov ntaub ntawv muab. Thaum hais kom muab lub npe ntawm cov ntawv, nco ntsoov qhia txoj hauv kev tshwj tsis yog cov ntawv nyob hauv tib phau ntawv teev npe li qhov program python. Txoj haujlwm tshem tawm cov ntaub ntawv hauv nws lub xeev dhau los, hloov nws nrog cov ntaub ntawv encrypted.aes, lossis txiav txim siab nws thiab hloov nws nrog cov ntawv qub.
Yav tom ntej, kuv yuav hloov kho qhov no kom suav nrog lub ntsej muag paub siv Python OpenCV lub tsev qiv ntawv, tab sis tam sim no tus password yuav tsum txaus.
Kauj Ruam 3: Kev Ua Haujlwm ntawm Cov Ntaub Ntawv
Txhawm rau khiav cov ntaub ntawv teeb tsa, ua raws cov theem no:
1. Ntaus hauv lub davhlau ya nyob twg:
python3 directory/setupname.py lo lus zais (hloov cov npe, teeb tsa lub npe, thiab tus password nrog lawv cov txiaj ntsig tshwj xeeb)
2. Lub davhlau ya nyob twg yuav tso koj cov ntaub ntawv tus lej. Khaws qhov no.
Txhawm rau ua haujlwm encryption/decryption program, ua raws cov theem no:
1. Ntaus hauv lub davhlau ya nyob twg:
python3 directory/filename.py password filenumber (hloov cov npe, npe npe, tus password, thiab tus lej npe nrog lawv qhov txiaj ntsig zoo)
2. Lub davhlau ya nyob twg yuav lees lossis tsis lees paub koj tus password. Yog tias tsis lees paub, sim dua thiab xyuas kom tseeb tias koj ntaus hauv qhov raug. Thaum tau txais kev tso cai, lub davhlau ya nyob twg yuav nug koj yog tias koj xav kom encrypt cov ntaub ntawv lossis khaws cov ntawv. Txhawm rau encrypt cov ntaub ntawv, ntaus e, thiab khaws cov ntaub ntawv encrypted, ntaus r.
3. Tom qab ntawd koj yuav raug nug kom muab lub npe cov ntaub ntawv. Nco ntsoov muab cov npe ntawm cov ntaub ntawv nrog rau lub npe, thiab tseem ua cov ntaub ntawv txuas ntxiv. Txawm li cas los xij, yog tias koj tab tom lees cov ntaub ntawv, tsis txhob ntaus.aes ib feem ntawm qhov txuas ntxiv, vim tias tus lej nyiaj rau qhov ntawd.
4. Qhov kev zov me nyuam tom qab ntawd encrypts lossis decrypts cov ntaub ntawv muab, thiab rho tawm cov ntawv hauv nws lub xeev dhau los (khaws cov ntaub ntawv encrypted lossis decrypted).
Voila! Ua tsaug rau qhov ua kom deb li qhov qhia tau, Kuv paub nyeem cov lej qhia tsis yog qhov lom zem tshaj plaws. Cov ntaub ntawv nab nab tau muab zais rau hauv cov theem no, rau cov ntawm koj uas xav muab qhov no txhaj. Ib zaug ntxiv, ua tsaug rau kev nyeem ntawv, thiab kuv xav kom koj muaj hmoov zoo hauv koj txoj kev sau npe yav tom ntej.
Pom zoo:
Nab hab sej txoj haujlwm - Cov paj laum uas tau koom nrog txhua hli/Kev tso nyiaj: 5 Kauj Ruam
Python Program - Sib Piv Cov Nyiaj Txiag Nrog Kev Pabcuam Ib Hlis/Deposit: Txoj haujlwm los laij cov paj laum nrog rau kev txhawb nqa txhua hli thaum kawg ntawm lub hlis. Tus lej suav los ntawm TheCalculatorSite.com: Muab cov paj laum rau tus thawj xibfwb: P (1+r/n)^(nt) Tus nqi yav tom ntej ntawm koob: PMT × (((1 + r/n)^nt - 1)/(r/n))
DIY Cheep/Cov Dej Ruaj Ruaj Ruaj Ruaj Ruaj Ruaj Ruaj Ruaj Zoo rau Tsiaj: 7 Kauj Ruam
DIY Cheep/Cov Dej Rhaub Dej Zoo rau Cov Tsiaj Tsiaj: Yog li koj tab tom khaws aub/luav/miv/… sab nraum thiab lawv cov dej ua kom khov thaum lub caij ntuj no. Tam sim no ib txwm koj yuav coj lawv mus sab hauv lossis yuav cov tais diav ua kom sov, tab sis cov tsiaj no tej zaum muaj ntxhiab tsw, koj tsis muaj chav nyob, thiab koj tsis tuaj yeem them $ 4
Nab hab sej rau Tsis Yog-Pib Pib Pib: 7 Kauj Ruam
Nab hab sej rau Tsis -Yog li Pib Pib: Nyob zoo, zaum kawg, yog tias koj tau mob siab rau, peb tau kov ntawm qhov pib ntawm nab nab - luam tawm, thaum thiab rau loops, nkag & tso tawm, yog, thiab pib ntawm easygui. kuj yog kev faib dawb pub dawb ntawm easygui thiab pycal-kuv tus kheej module.this nyeem yuav suav nrog: ntau dua
Txaus Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Rov Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Txim Tawm Txav Txim Txim Kom Txav Txim Txim Txim Txim Nthuav Tshab Txhab Txhab Txhab Txim Kom Txav Txim: 4 Kauj Ruam
Txaus Txiaj Ntsig Zoo Tshaj Plaws: Nyob zoo cov phooj ywg, hauv cov lus qhia no, Kuv yuav qhia koj li cas kuv thiaj ua lub hwj huam nqa tau uas tuaj yeem siv ua cov cuab yeej rau cov haujlwm nyiam ua haujlwm, tau kawg muaj cov khoom siv hluav taws xob zoo li qhov no hauv kev qhia, tab sis qhov no muaj peb qhov zoo, 1) yog
Tsho Ruaj Ntseg Ruaj Ntseg: Kev Ruaj Ntseg Ris Tsho LED Tsho: 11 Cov Kauj Ruam (nrog Duab)
Ris tsho Ruaj Ntseg Ruaj Ntseg: Kev Ruaj Ntseg Zoo LED Jacket: Txhim kho lub teeb yuag thiab siv tau cov khoom siv hluav taws xob tau qhib qhov muaj peev xwm tshiab rau kev siv thev naus laus zis mus rau hauv lub tebchaws thiab siv nws los ua kom muaj kev nyab xeeb ntawm cov neeg tshawb nrhiav. Txog rau qhov haujlwm no, Kuv kos kuv tus kheej kev paub nrog kev tawm sab nraud