(* Copyright 2012-2015 by Adam Petcher.				* * Use of this source code is governed by the license described	* * in the LICENSE file at the root of the source tree.		*)
(* Construction of a pseudorangom generator from a one-way permutations on bit vector with an associated hard core predicate. *)
Set Implicit Arguments.
Section OneWayPermutation.
Variable n : nat.
Variable f : Bvector n -> Bvector n.
Variable f_inv : Bvector n -> Bvector n.
Hypothesis f_inv1 : forall v, f (f_inv v) = v.
Hypothesis f_inv2 : forall v, f_inv (f v) = v.
Variable A : Bvector n -> Comp (Bvector n).
Definition OWP_G :=
c <-$ {0, 1} ^ n;
a <-$ A (f c);
ret (eqb a c).
Definition OWP_Advantage := | (Pr[OWP_G])  - (1 / (2 ^ n)) |.
End OneWayPermutation.
Section HardCorePredicate.
Variable n : nat.
Variable f : Bvector n -> Bvector n.
Variable b : Bvector n -> bool.
Variable A : Bvector n -> bool -> Comp bool.
Definition HCP_G1 :=
r <-$ {0, 1} ^ n;
g <-$ (A (f r) (b r));
ret g.
Definition HCP_G2 :=
rb <-$ {0, 1};
r <-$ {0, 1} ^ n;
g <-$ (A (f r) rb);
ret g.
Definition HCP_Advantage := | (Pr[HCP_G1]) - (Pr[HCP_G2]) | .
End HardCorePredicate.
Definition vector_firstPart_h(A : Set)(m1 m2 : nat)(v : Vector.t A (m1 + m2)) : {ls : list A | length ls = m1}.
refine (exist _ (firstn m1 (Vector.to_list v)) _).
eapply eq_trans.
apply firstn_length.
rewrite to_list_length.
eapply min_l.
omega.
Defined.
Fixpoint firstPart(A : Set)(m1 m2 : nat)(v : Vector.t A (m1 + m2)) : Vector.t A m1 :=
of_sig_list (vector_firstPart_h m1 m2 v).

(* Specifications: *)
Theorem skipn_length : forall (A : Set) n0 (ls : list A),
length (skipn n0 ls) = (length ls) - n0.