Guest User

shitscript

a guest
Nov 20th, 2024
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | Cybersecurity | 0 0
  1. import hashlib
  2. from Crypto.Cipher import AES
  3. from Crypto.Util.Padding import pad, unpad
  4. import argparse
  5. import os
  6.  
  7. # Parameters
  8. DIFFICULTY = 5 # Number of leading zeros in hash
  9. BLOCK_SIZE = 16 # AES block size
  10.  
  11.  
  12. # Encrypt the hidden link
  13. def encrypt_link(link, key):
  14. cipher = AES.new(key, AES.MODE_ECB)
  15. encrypted_link = cipher.encrypt(pad(link.encode(), BLOCK_SIZE))
  16. return encrypted_link
  17.  
  18.  
  19. # Decrypt the hidden link
  20. def decrypt_link(encrypted_link, key):
  21. cipher = AES.new(key, AES.MODE_ECB)
  22. decrypted_link = unpad(cipher.decrypt(encrypted_link), BLOCK_SIZE).decode()
  23. return decrypted_link
  24.  
  25.  
  26. # Generate a challenge
  27. def generate_challenge(link, difficulty):
  28. challenge = os.urandom(16).hex() # Random 16-byte challenge
  29. print(f"Challenge: {challenge}")
  30. key = hashlib.sha256(challenge.encode()).digest()[:BLOCK_SIZE] # Derive key
  31. encrypted_link = encrypt_link(link, key)
  32. return challenge, encrypted_link
  33.  
  34.  
  35. # Solve the challenge
  36. def find_nonce(challenge, difficulty):
  37. target = "0" * difficulty
  38. nonce = 0
  39. while True:
  40. guess = f"{challenge}{nonce}".encode()
  41. hash_result = hashlib.sha256(guess).hexdigest()
  42. if hash_result.startswith(target):
  43. return nonce, hash_result
  44. nonce += 1
  45.  
  46.  
  47. # Verify the solution and reveal the link
  48. def verify_solution(challenge, nonce, encrypted_link, difficulty):
  49. guess = f"{challenge}{nonce}".encode()
  50. hash_result = hashlib.sha256(guess).hexdigest()
  51. if not hash_result.startswith("0" * difficulty):
  52. print("Invalid solution. The hash does not meet the difficulty requirement.")
  53. return None
  54. key = hashlib.sha256(challenge.encode()).digest()[:BLOCK_SIZE]
  55. return decrypt_link(encrypted_link, key)
  56.  
  57.  
  58. # Main program
  59. def main():
  60. parser = argparse.ArgumentParser(description="GPU Hard Challenge with Hidden Link")
  61. parser.add_argument("--generate", action="store_true", help="Generate a new challenge")
  62. parser.add_argument("--solve", action="store_true", help="Solve a given challenge")
  63. parser.add_argument("--verify", action="store_true", help="Verify a solution and reveal the link")
  64. parser.add_argument("--link", type=str, help="Hidden link to encrypt")
  65. parser.add_argument("--challenge", type=str, help="Challenge string")
  66. parser.add_argument("--nonce", type=int, help="Nonce to verify solution")
  67. parser.add_argument("--encrypted", type=str, help="Encrypted link (hex-encoded)")
  68. args = parser.parse_args()
  69.  
  70. if args.generate:
  71. if not args.link:
  72. print("Please provide a link using --link.")
  73. return
  74. challenge, encrypted_link = generate_challenge(args.link, DIFFICULTY)
  75. print(f"Challenge: {challenge}")
  76. print(f"Encrypted Link (hex): {encrypted_link.hex()}")
  77. print("Share the challenge and encrypted link with the solver.")
  78.  
  79. elif args.solve:
  80. if not args.challenge:
  81. print("Please provide a challenge using --challenge.")
  82. return
  83. nonce, hash_result = find_nonce(args.challenge, DIFFICULTY)
  84. print(f"Found Nonce: {nonce}")
  85. print(f"Hash Result: {hash_result}")
  86.  
  87. elif args.verify:
  88. if not args.challenge or not args.nonce or not args.encrypted:
  89. print("Please provide --challenge, --nonce, and --encrypted.")
  90. return
  91. encrypted_link = bytes.fromhex(args.encrypted)
  92. link = verify_solution(args.challenge, args.nonce, encrypted_link, DIFFICULTY)
  93. if link:
  94. print(f"Hidden Link: {link}")
  95.  
  96. else:
  97. print("Please specify an action: --generate, --solve, or --verify.")
  98.  
  99.  
  100. if __name__ == "__main__":
  101. main()
  102.  
Advertisement
Add Comment
Please, Sign In to add comment