Laptop19

Untitled

Dec 3rd, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.34 KB | Source Code | 0 0
  1. 1.
  2. def caeser(text,mode,key):
  3.     res=""
  4.     for i in text:
  5.         if i.islower():
  6.             if mode=="encrypt":
  7.                 res+=chr((ord(i)+key-97)%26+97)
  8.             else:
  9.                 res+=chr((ord(i)-key-97)%26+97)
  10.         elif i.isupper():
  11.             if mode=="encrypt":
  12.                 res+=chr((ord(i)+key-65)%26+65)
  13.             else:
  14.                 res+=chr((ord(i)-key-65)%26+65)
  15.         else:
  16.             res+=i
  17.     return res
  18.  
  19. print(caeser("KHOOR zruog","decrypt",3))
  20.  
  21.  
  22. 2.
  23. def encrypt(text,rails):
  24.     text=text.replace(" ","").upper()
  25.     fence=[[] for i in range(rails)]
  26.     rail=0
  27.     step=1
  28.     for i in text:
  29.         fence[rail].append(i)
  30.         rail+=step
  31.         if rail==0 or rail==rails-1:
  32.             step*=-1
  33.     cipher=""
  34.     for i in fence:
  35.         cipher+="".join(i)
  36.     print(cipher)
  37. encrypt("geeks for geeks",3)
  38.  
  39. def decrypt(cipher,rails):
  40.     fence=[[""]*len(cipher) for i in range(rails)]
  41.     rail=0
  42.     step=1
  43.     for i in range(len(cipher)):
  44.         fence[rail][i]="*"
  45.         rail+=step
  46.         if rail==0 or rail==rails-1:
  47.             step*=-1
  48.     k=0
  49.     for i in range(rails):
  50.         for j in range(len(cipher)):
  51.             if fence[i][j]=="*":
  52.                 fence[i][j]=cipher[k];k+=1
  53.     text=""
  54.     rail=0
  55.     step=1
  56.     for i in range(len(cipher)):
  57.         text+=fence[rail][i]
  58.         rail+=step
  59.         if rail==0 or rail==rails-1:
  60.             step*=-1
  61.     print(text)
  62. decrypt("GSGSEKFREKEOE",3)
  63.  
  64.  
  65. 3.
  66. import hashlib
  67. def hashing(password):
  68.     sha=hashlib.sha256()
  69.     enco=password.encode("utf-8")
  70.     sha.update(enco)
  71.     return sha.hexdigest()
  72.  
  73. print((hashing("")))
  74.  
  75.  
  76. 4.
  77. import hashlib
  78. import requests
  79. def check_pwned(password):
  80.     hash_pass=hashlib.sha1(password.encode("utf-8")).hexdigest().upper()
  81.     prefix=hash_pass[:5]
  82.     suffix=hash_pass[5:]
  83.     url=f"https://api.pwnedpasswords.com/range/{prefix}"
  84.     response=requests.get(url)
  85.     if response.status_code!=200:
  86.         return -1
  87.     hash=response.text.splitlines()
  88.     for i in hash:
  89.         suffiix,count=i.split(":")
  90.         if suffix==suffiix:
  91.             return int(count)
  92. f=open("meri.txt")
  93. for i in f:
  94.     l=i.strip()
  95.     username,password=l.split(",")
  96.     c=check_pwned(password)
  97.     if c<0:
  98.         print("api error")
  99.     elif c>0:
  100.         print("pass found ",c)
  101.     else:
  102.         print("pass not found")
  103.  
  104. For this if required
  105. pip install requests
  106.  
  107.  
  108. meri.txt file content format-,
  109. username1,password1
  110. username2,password2
  111.  
  112.  
  113. 5.
  114. import random
  115. f=open("diction.txt")
  116. w=f.readlines()
  117. for i in range(len(w)):
  118.     w[i]=w[i].strip("\t\n")
  119. rlist=random.sample(w,3)
  120. print("".join(rlist))
  121. f.close()
  122.  
  123.  
  124. diction.txt
  125. mountain   
  126. silent 
  127. climb  
  128. journey
  129. ocean  
  130. brilliant  
  131. whisper
  132. inspire
  133. shadow 
  134. emerald
  135. discover   
  136. courage
  137. wizard 
  138. hidden 
  139. wander 
  140. triumph
  141. rocket 
  142.  
  143.  
  144. 6.
  145. import itertools
  146. import string
  147. password = "dogyy"   # the target password (small for demo)
  148. chars = string.ascii_lowercase  # allowed characters: a–z
  149. attempts = 0
  150. for length in range(1, 6):  # try length 1 to 5
  151.     for combo in itertools.product(chars, repeat=length):
  152.         attempts += 1
  153.         guess = "".join(combo)
  154.         if guess == password:
  155.             print("Password found:", guess)
  156.             print("Attempts:", attempts)
  157.             exit()
  158. print("Password not found")
Advertisement
Add Comment
Please, Sign In to add comment