0% found this document useful (0 votes)
17 views7 pages

DP Practical File

Data privacy

Uploaded by

Disha Prashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

DP Practical File

Data privacy

Uploaded by

Disha Prashar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 7
‘2924, 7:29 PM DP practical 1.pynt- Colab | Write a progran to perfarn encryption and decryption using Caesar cipher(substitutional cipher) det eneryet ne, offset) ‘Foo £ An eange(ten(text)): ‘har = text] 6 char.ssvaper() result e= chr((ord(enar) + offset = 65) % 26 « 65) ‘if enar-islower() ronult t= chr((ord(char) + offaet ~ 97) % 26 + 97) det decrygt (text, offset) return encrygt(text, -of4set) text = input ("Enter she text t9 eneryatt offset = ant(ingut("enter the offset for encryption: *)) snerypted = encrypt(text, offset) print(Encrypted text ia!-", encrypted) decrypted = cecrypt(encrypted, e##set) printt"Deceypted text is!-", decrypted) Enter the offset for encryption: 7 Encrypted text tat= voll bow h apt Decrypted text 15: once upon 2 Eine ‘ntps:ifeolab research google. comvdrvaig-aqiTRTFnpkNeYSPoGdbY 1UAZiosZHiscrolTo=rOyXKb XXG._B&priniMode=tue wn ‘2924, 7:94 PM DP practical .ipynt- Colab # Write 2 prosran to perform encryption and decryption using RBil Fence cipher(transpositional cipher) det enerypt(text, key): rail = (L\8" for 1 sn oa sown gir = False row col = 8, @ for 4 An nange(len¢text)): 46 row on 8 or row n= key = 1 rati{rou}{eel] = texts] 4 omar ease result = (1 for in range(eey) ‘Yor j An range(lenttext)): ef ratt(4]0)) I= result. append(rail(41(4)) return" Jotn(vesult) der decrypt(etprer, key) all = [["\e" for 1 in range(len(esgher))] for 5 sm rangeceey)) own. sir = None row, col = 8, 8 for 4 An rangeClen¢cipher)): own air = True ratt{rou)(col] = coed 6 coun ae for {An rangechey) ‘or 4 an rangetlen(cipner)) S (eRAL[A][3] == 17"). a8 (Andex < Len(ctpner)) Pai1[HIC3] » cipherfineexd finders 2 result = U1 for Cn mange (aen(espher)) if row a= 8 serow ne May = own_sir = False if rait{row}teot) | result. appena(rati[rowdfeot]) $f ott ease return "*Jotn(vesult) ntpssioolab res rch google. comidriv id. WY SwVaRrEdEg ViolVBqSenzl6YxtprntMode=true ‘12924, 7:94 PM DP practical .ipynt- Colab text = input ("Enter she text t9 eneryat® *) key = Ane(inpus("enten the key for eneryption: °)) cnerypted = cnerypt(sent, ey) print" Encrypted text 4:- {encrypted} decrypted = cecrypt(ancryptes, tay) printf’ decrypted text 5!~ (aecrypted)") ST enter the kay fot encryption: Encrypted text ds:" hetene Decrypted text 15:- herant ntps:ifolab research google.comvérv! id. WY’SwrVaRrEdEg ViolVBqSenz/6YxtiprntMode=true ‘2924, 7:95 PM DP practical 3.pynt- Colao snport hase det hash password(pasiverd: str) > ste 1 create a 8-256 hash object shaB56 hash = hashib.sha256() 4 Update the hash object with the bytes of the password string shad56_hasn.opeate(passwors.encode("utt-8")) 4 Get the hoxadecinat cepresertation of the hash hashed password = shi25é_hach-hexdigest() return hashed password 4 Granpte usage Sf none oe nai 7 Input passvora fron user user_passierd > input ("enter your passworé: *) {Hash the password hashed password = hash password (user_password) 4 Print the hashed password peine(#"SHt-256 hashed password: {hashed password}") Enter your passiord: once ‘SIUS256 hashed passwords 20065350h265912F6924D9946Sz7JA7EBGaSedGEAAF4BFIbISeDbeLA9.S7E5E Intps:folab research google.comidrvelz#lgywS_xfRIMSKPB2EIKGSsPYC7m4yDifprintMode=true wn ‘2924, 7:95 PM DP practical 4 ipynt -Colab # opening fide and writing usernames and passwords in it weseh open('info.tat, ow") 38-1 sta = [C'usert", “passnord’), (useraé, ‘passt23e"), (‘user3', “djfdgaohfoart")] for uiernane, password in date ‘wt #(asernane), (password) wan open('infa. tat", 'e!) 38 printtf.reae()) ‘ser3,a5thagaohfoant 1 tmponting necessary Libraries nport hasnise| + opening fide for reading cara tien open('anfo.tat, 'n') 96 ‘4 iterating over each urerrane and password for line in f ser, patoword = ines strip()caplit(") 4 converting the password to hash and hexadecinal in uppercase using Siti, hendigest and upper functions pass_nash = hashlib, sna (password. ancode("utf-8")) nexdigest() upper 4 calling A71 to get the Leaked passwords by matching the first 5 letters of password hash response = requests. get (#"https://apl.pwncerasswards. con 1 checking status of response for the passuard(returns 200 1¢ respanse is suecessfu) 4 response. status code == 200 a spliteing the aatching mashes hashes = response text. splitLines() count = © # Keeping track how many tines the password = Leaked fs iterating through a1 watering hashes for nash suffix sn hashes ‘t Parsnora 4s leaked 1f the password hash matches with response hash completely 1 hosh_suffbe-split('s")[8) == poss hash] Dprine(?"Password for user {user} has Been Leakee") sf coun = 0) printt¢"Password for user (user) has not been Leaked") ‘cannot search the pastiord sf response statue is not 200 ose Print("Camot searen for password") FE rassword for user user has been Leaked Password for user user3 has not been leaked ‘ntps:ifeolab research google. comvdrveG0x"imiZH7FNYAQUEWx3GxguBedROHEDHApriniMode=true ‘2924, 7:95 PM DP practical S.ipyn- Colao utte » python program that generates # passward using 9 random combination of words fron a aictionary ‘le snport andon| onde = 0 for i in range(2s) ‘weeds -apperache(6S+8)) lends apperatene(9744)) det passnore_generaton(Length, words): password = for i in range(lengsh) ‘ncex » randon-rancine(@, 1) ptserd so wordaflnden] sength = inetinput{"Enter the length of the password: *)) passwone = password generator length, worés) Drint(/"The randomly generates password ts (poeshore)") Enter the Leagth of the passiord : 7 ‘ine randonly generated password is Qucifl wn ‘172924, 7:96 PM DP practical 6.ipynt- Colao # uite » python program that sinulates a brute-force attack on a passore Sy trying out all possible charseser combinations snport teertools et veute_force_attack(password: cnaractans = “abederghl jk moperstuvaay2A6COEFGHEKLANOPQRSTUYNKYZ0123455760 snax_Length ~ len(paseword) for rin range, maxiength + 2) ‘or combo in product(enaracters, repeat =r) SF" Jota(conte) a= passnor print(e"Passward Found after {count} ateanots: (°°. join conbo)}") password = input("Enter the password to attack! °) brute_force_sttack(passvord) Password found after 13123043 sttenpts: 26f4 -ntps:ifolab research google. comdrve/1BOXq-BONCoMBAeGOKFIESMabnxBqTKukifprintMode=tue "

You might also like