跳到主内容
paste
bin
.ca
type · paste · share
⌘
K
登录
?
账户
更多
▾
文档
系列
bin 系列
pastebin.ca
中心
Share text and code with expiry and privacy controls.
imagebin.ca
Upload and share images with direct links.
filebin.ca
Drop a file and get a shareable link.
notebin.ca
Write Markdown notes with durable links.
turl.ca
Short, reputation-checked links.
attn.ca
Notifications and alerts for your services.
voicebin.ca
Record and share short voice clips.
dnsbin.ca
Inspect DNS and debug records.
← 返回文本
›
编辑 / 分支
无标题文本
#2ASf2F2wg4
public / public
新版本
匿名
已创建 24 hours ago
过期于 6 days
8.1 KB
语法:
text
你的更改会创建一个链接到此文本的新文本 — 原始文本不变。
新版本
你的更改会创建一个链接到此文本的新文本 — 原始文本不变。
标题(可选)
文件名
语法
text
text
bash
c
cpp
css
diff
dockerfile
go
html
ini
java
javascript
json
kotlin
lua
makefile
markdown
nginx
php
python
ruby
rust
shellscript
sql
swift
toml
typescript
xml
yaml
可见性
公开动态
访问
public
过期
7 天
10 分钟
1 小时
1 天
7 天
30 天
90 天
自定义…
自定义过期
变更备注
(可选)
任何人都能在公开动态中找到此文本。选择“未列出”即可仅通过链接分享。
创建新版本
取消
粘贴或输入…
import java.util.Scanner; public class CaesarCipher { // Moves every letter k places forward in the alphabet, wrapping Z back to A static String shift(String str, int k) { String result = ""; for (char c : str.toCharArray()) { if (Character.isUpperCase(c)) c = (char) ('A' + (c - 'A' + k) % 26); else if (Character.isLowerCase(c)) c = (char) ('a' + (c - 'a' + k) % 26); result += c; } return result; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter any String: "); String str = sc.nextLine(); System.out.print("\nEnter the Key: "); int key = sc.nextInt() % 26; String encrypted = shift(str, key); System.out.println("\nEncrypted String is: " + encrypted); System.out.println("\nDecrypted String is: " + shift(encrypted, 26 - key)); System.out.println(); } } _______3.b import java.util.Scanner; public class SubstitutionCipher { public static void main(String[] args) { String a = "abcdefghijklmnopqrstuvwxyzH"; String b = "zyxwvutsrqponmlkjihgfedcbaS"; System.out.print("Enter any string: "); String str = new Scanner(System.in).nextLine(); String encrypted = ""; for (char c : str.toCharArray()) encrypted += b.charAt(a.indexOf(c)); // partner letter from b System.out.println("The encrypted data is: " + encrypted); } } _________des algo import java.util.Base64; import java.util.Scanner; import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; import javax.crypto.spec.DESedeKeySpec; public class DES { public static void main(String[] args) throws Exception { System.out.print("Enter the string: "); String text = new Scanner(System.in).nextLine(); byte[] keyBytes = "ThisIsSecretEncryptionKey".getBytes("UTF8"); SecretKeyFactory factory = SecretKeyFactory.getInstance("DESede"); SecretKey key = factory.generateSecret(new DESedeKeySpec(keyBytes)); Cipher cipher = Cipher.getInstance("DESede"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encryptedBytes = cipher.doFinal(text.getBytes("UTF8")); String encrypted = Base64.getEncoder().encodeToString(encryptedBytes); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decryptedBytes = cipher.doFinal(Base64.getDecoder().decode(encrypted)); String decrypted = new String(decryptedBytes, "UTF8"); System.out.println("\nString To Encrypt : " + text); System.out.println("Encrypted Value : " + encrypted); System.out.println("Decrypted Value : " + decrypted); } } _______ blowfish import java.util.Base64; import java.util.Scanner; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; public class BlowFish { public static void main(String[] args) throws Exception { KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish"); keyGenerator.init(128); Cipher cipher = Cipher.getInstance("Blowfish/CFB/NoPadding"); cipher.init(Cipher.ENCRYPT_MODE, keyGenerator.generateKey()); System.out.println("Initialization Vector of the Cipher: " + Base64.getEncoder().encodeToString(cipher.getIV())); System.out.print("Enter text to encrypt: "); String text = new Scanner(System.in).nextLine(); byte[] encrypted = cipher.doFinal(text.getBytes()); System.out.println("Encrypted Text: " + Base64.getEncoder().encodeToString(encrypted)); } } _______rij aglo import java.util.Scanner; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class AES { static String asHex(byte[] bytes) { String hex = ""; for (byte b : bytes) hex += String.format("%02x", b); return hex; } public static void main(String[] args) throws Exception { System.out.print("Enter the data to be encrypted: "); String message = new Scanner(System.in).nextLine(); KeyGenerator kgen = KeyGenerator.getInstance("AES"); kgen.init(128); SecretKey key = kgen.generateKey(); Cipher cipher = Cipher.getInstance("AES"); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encrypted = cipher.doFinal(message.getBytes("UTF-8")); System.out.println("Encrypted string: " + asHex(encrypted)); cipher.init(Cipher.DECRYPT_MODE, key); byte[] original = cipher.doFinal(encrypted); System.out.println("Original string: " + new String(original, "UTF-8")); System.out.println("Original data in hexadecimal: " + asHex(original)); } } _____rc4 import java.util.Scanner; import javax.crypto.Cipher; import javax.crypto.KeyGenerator; import javax.crypto.SecretKey; public class BlowFishCipher { public static void main(String[] args) throws Exception { SecretKey key = KeyGenerator.getInstance("Blowfish").generateKey(); Cipher cipher = Cipher.getInstance("Blowfish"); System.out.print("Input your message: "); String text = new Scanner(System.in).nextLine(); cipher.init(Cipher.ENCRYPT_MODE, key); byte[] encrypted = cipher.doFinal(text.getBytes("UTF-8")); String hex = ""; for (byte b : encrypted) hex += String.format("%02X", b); cipher.init(Cipher.DECRYPT_MODE, key); byte[] decrypted = cipher.doFinal(encrypted); System.out.println("Encrypted text: " + hex); System.out.println("Decrypted text: " + new String(decrypted, "UTF-8")); } } ________rsa import java.math.BigInteger; import java.util.Random; import java.util.Scanner; public class RSA { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.print("Enter a Prime number: "); BigInteger p = sc.nextBigInteger(); System.out.print("Enter another prime number: "); BigInteger q = sc.nextBigInteger(); BigInteger n = p.multiply(q); BigInteger one = BigInteger.ONE; BigInteger phi = p.subtract(one).multiply(q.subtract(one)); // Pick a random e (greater than 2) with gcd(e, phi) = 1 Random r = new Random(); BigInteger e; do { e = BigInteger.valueOf(r.nextInt(phi.intValue() - 1)); } while (e.intValue() <= 2 || !phi.gcd(e).equals(BigInteger.ONE)); BigInteger d = e.modInverse(phi); // d x e = 1 (mod phi) System.out.println("Encryption keys are: " + e + ", " + n); System.out.println("Decryption keys are: " + d + ", " + n); } } ____hellman import java.math.BigInteger; import java.security.KeyFactory; import java.security.KeyPairGenerator; import java.security.SecureRandom; import javax.crypto.spec.DHParameterSpec; import javax.crypto.spec.DHPublicKeySpec; public class DiffeHellman { // Generates a key pair and prints its public key static void printPublicKey(KeyPairGenerator kpg) throws Exception { DHPublicKeySpec kspec = KeyFactory.getInstance("DiffieHellman") .getKeySpec(kpg.generateKeyPair().getPublic(), DHPublicKeySpec.class); System.out.println("Public key is: " + kspec); } public static void main(String[] args) throws Exception { KeyPairGenerator kpg = KeyPairGenerator.getInstance("DiffieHellman"); kpg.initialize(512); printPublicKey(kpg); SecureRandom rnd = new SecureRandom(); BigInteger p = BigInteger.probablePrime(512, rnd); BigInteger g = BigInteger.probablePrime(512, rnd); kpg.initialize(new DHParameterSpec(p, g)); System.out.println(); printPublicKey(kpg); } } _____ Program import java.security.MessageDigest; public class SHA1 { public static void main(String[] args) throws Exception { MessageDigest md = MessageDigest.getInstance("SHA1"); System.out.println("Message digest object info: "); System.out.println(" Algorithm = " + md.getAlgorithm()); System.out.println(" Provider = " + md.getProvider()); System.out.println(" ToString = " + md); String[] inputs = { "", "abc", "abcdefghijklmnopqrstuvwxyz" }; for (String input : inputs) { String hex = ""; for (byte b : md.digest(input.getBytes())) hex += String.format("%02X", b); System.out.println("\nSHA1(\"" + input + "\") = " + hex); } System.out.println(); } } ____md5 import java.security.MessageDigest; public class MD5 { public static void main(String[] args) throws Exception { MessageDigest md = MessageDigest.getInstance("MD5"); System.out.println("Message digest object info: "); System.out.println(" Algorithm = " + md.getAlgorithm()); System.out.println(" Provider = " + md.getProvider()); System.out.println(" ToString = " + md); String[] inputs = { "", "abc", "abcdefghijklmnopqrstuvwxyz" }; for (String input : inputs) { String hex = ""; for (byte b : md.digest(input.getBytes())) hex += String.format("%02X", b); System.out.println("\nMD5(\"" + input + "\") = " + hex); } System.out.println(); } } _______