3.20 For a function g: {0, 1 }n --+ {0, 1}n, let g$(·) be an oracle that, on inp
ID: 3862643 • Letter: 3
Question
3.20 For a function g: {0, 1 }n --+ {0, 1}n, let g$(·) be an oracle that, on input 1n, chooses r +- {0, 1 }n uniformly at random and returns (r, g (r)). We say a keyed function F is a weak pseudorandom function if for all PPT algorithms D, there exists a negligible function negl such that:
| pr [ D^f^s (.) (1^n) =1] - pr [ D^f^s (.) (1^n) =1 ] | <= negl (n),
where k <-- {0, l }^n and f <-- Func n are chosen uniformly at random
(a) Prove that if F is pseudorandom then it is weakly pseudorandom.
(b) Let F' be a pseudorandom function, and define · .
Fk (x)=F`k(x)if x is even k . F`k(x+1) if x is odd
Prove that F is weakly pseudorandom, but not pseudorandom.
(c) Is counter-mode encryption instantiated using a weak pseudorandom function F necessarily CPA-secure? Does. it necessarily have indistinguishable encryptions in the presence of an eavesdropper? Prove your answers.
(d) Construct a CPA-secure encryption scheme based on a weak pseudorandom function. Hint: One of the constructions in this chapter will work.
This question from introduction to modern cryptography book chapter 3 question 3.20
Explanation / Answer
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class KeyGenerator {
Random rr=new Random();
public int getKeys(){
String str="";
str=String.valueOf(rr.nextInt(10))+String.valueOf(rr.nextInt(10))+String.valueOf(rr.nextInt(10))+String.valueOf(rr.nextInt(10))+String.valueOf(rr.nextInt(10))+String.valueOf(rr.nextInt(10));
return Integer.parseInt(str);
}
public static void main(String args[]){
KeyGenerator Generator = new KeyGenerator();
System.out.println(Generator.getKeys());import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.spec.SecretKeySpec;
public class CryptoUtils {
private static final String ALGORITHM = "AES";
private static final String TRANSFORMATION = "AES";
public static void encrypt(String key, File inputFile, File outputFile)
throws CryptoException {
doCrypto(Cipher.ENCRYPT_MODE, key, inputFile, outputFile);
}
public static void decrypt(String key, File inputFile, File outputFile)
throws CryptoException {
doCrypto(Cipher.DECRYPT_MODE, key, inputFile, outputFile);
}
private static void doCrypto(int cipherMode, String key, File inputFile,
File outputFile) throws CryptoException {
try {
Key secretKey = new SecretKeySpec(key.getBytes(), ALGORITHM);
Cipher cipher = Cipher.getInstance(TRANSFORMATION);
cipher.init(cipherMode, secretKey);
FileInputStream inputStream = new FileInputStream(inputFile);
byte[] inputBytes = new byte[(int) inputFile.length()];
inputStream.read(inputBytes);
byte[] outputBytes = cipher.doFinal(inputBytes);
FileOutputStream outputStream = new FileOutputStream(outputFile);
outputStream.write(outputBytes);
inputStream.close();
outputStream.close();
} catch (NoSuchPaddingException | NoSuchAlgorithmException
| InvalidKeyException | BadPaddingException
| IllegalBlockSizeException | IOException ex) {
throw new CryptoException("Error encrypting/decrypting file", ex);
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.