text stringlengths 0 601k |
|---|
let ( ) = let v = ref 0 in for l = 0 to 7 do for c = 0 to 7 do let j = 8 * l + c in if c < 7 then begin m . ( ! v ) . ( j ) <- true ; m . ( ! v ) . ( j + 1 ) <- true ; incr v ; end ; if l < 7 then begin m . ( ! v ) . ( j ) <- true ; m . ( ! v ) . ( j + 8 ) <- true ; incr v ; end ; done done |
let col j = let rec make acc i = if i = n then acc else make ( if m . ( i ) . ( j ) then i :: acc else acc ) ( i + 1 ) in make [ ] 0 |
let bdd = let rec make bdd j = if j = 64 then bdd else let cell_j = List . fold_left in make ( mk_and bdd cell_j ) ( j + 1 ) in make one 0 |
let ( ) = printf " % Ld solutions . " @ ( count_sat bdd ) |
let ( ) = let s = random_sat bdd in List . iter ( fun ( v , b ) -> let i = v - 1 in if b then begin end ) s |
} | tm_sec : int ; tm_min : int ; tm_hour : int ; tm_mday : int ; tm_mon : int ; tm_year : int ; tm_wday : int ; tm_yday : int ; tm_isdst : int } [ @@ as_record ] |
let _EOVERFLOW = [ % c constant " EOVERFLOW " sint ] |
let ( ) = let timep = allocate_n ~ count : 1 time_t in let time = time timep in assert ( time = !@ timep ) ; let ptm = match localtime timep with | None -> prerr_endline " localtime failure " ; exit 1 | Some s -> s in let tm = !@ ptm in Printf . printf " tm . tm_mon = % d \ n " tm . tm_mon ; Printf . printf " tm . tm_y... |
module Protocol = struct type t = int64 include ( Compare . Int64 : Compare . S with type t := int64 ) let epoch = 0L let diff = Int64 . sub let add = Int64 . add let of_ptime t = let ( days , ps ) = Ptime . Span . to_d_ps ( Ptime . to_span t ) in let s_days = Int64 . mul ( Int64 . of_int days ) 86_400L in Int64 . add ... |
module System = struct let frac_s = 3 type t = Ptime . t include Compare . Make ( Ptime ) let epoch = Ptime . epoch module Span = struct type t = Ptime . Span . t let multiply_exn f s = let open Ptime . Span in WithExceptions . Option . to_exn ~ none ( : Failure " Time . System . Span . multiply_exn " ) ( of_float_s ( ... |
let ( ) = Data_encoding . Registration . register ~ pp : Protocol . pp_hum Protocol . encoding ; Data_encoding . Registration . register ~ pp : System . pp_hum System . encoding ; Data_encoding . Registration . register System . Span . encoding |
module type Basic = sig module Span : Span_intf . S type t module Replace_polymorphic_compare : Comparable . Polymorphic_compare with type t := t include Comparable . Polymorphic_compare with type t := t include Robustly_comparable with type t := t val add : t -> Span . t -> t val sub : t -> Span . t -> t val diff : t ... |
module type S = sig type underlying type t = private underlying [ @@ deriving bin_io , compare , hash , typerep ] module Span : Span_intf . S with type underlying = underlying module Ofday : Ofday_intf . S with type underlying := underlying and module Span := Span include Basic with type t := t and module Span := Span ... |
let of_iso8601_exn ' of_iso8601 s = match of_iso8601 s with | Ok x -> x | Error msg -> raise ( ISO8601_parse_exn msg ) |
let str_of_pp pp x = Fmt . str " % a " pp x |
module Ym = struct include Ym let pp_iso8601 = ISO8601_printers . pp_ym let to_iso8601 x = str_of_pp pp_iso8601 x let of_iso8601 = ISO8601_parsers . ym_of_str let of_iso8601_exn s = of_iso8601_exn ' of_iso8601 s end |
module ISO_week = struct include ISO_week let pp_iso8601 = ISO8601_printers . pp_iso_week let to_iso8601 x = str_of_pp pp_iso8601 x let of_iso8601 = ISO8601_parsers . iso_week_of_str let of_iso8601_exn s = of_iso8601_exn ' of_iso8601 s end |
module Date = struct include Date let pp_rfc3339 = RFC3339 . pp_date let to_rfc3339 x = str_of_pp pp_rfc3339 x let of_iso8601 = ISO8601_parsers . date_of_str let of_iso8601_exn s = of_iso8601_exn ' of_iso8601 s let to_sexp = To_sexp . sexp_of_date let to_sexp_string x = CCSexp . to_string ( To_sexp . sexp_of_date x ) l... |
module Time = struct include Time let pp_rfc3339 = RFC3339 . pp_time let pp_rfc3339_milli = pp_rfc3339 ~ frac_s : frac_s_milli ( ) let pp_rfc3339_micro = pp_rfc3339 ~ frac_s : frac_s_micro ( ) let pp_rfc3339_nano = pp_rfc3339 ~ frac_s : frac_s_nano ( ) let to_rfc3339 = RFC3339 . of_time let to_rfc3339_milli = to_rfc333... |
module Span = struct include Span module For_human = struct include For_human ' let to_string = Printers . string_of_span_for_human let pp = Printers . pp_span_for_human end let to_string = Printers . string_of_span let pp = Printers . pp_span let to_sexp = To_sexp . sexp_of_span let to_sexp_string x = CCSexp . to_stri... |
module Timestamp = struct include Span let min_val = timestamp_min let max_val = timestamp_max let now = timestamp_now let pp = Printers . pp_timestamp let to_string = Printers . string_of_timestamp let pp_rfc3339 = RFC3339 . pp_timestamp let pp_rfc3339_milli = pp_rfc3339 ~ frac_s : frac_s_milli ( ) let pp_rfc3339_micr... |
let to_string = Printers . string_of_date_time Printers . Date_time_cannot_deduce_offset_from_utc |
let pp_rfc3339_milli = pp_rfc3339 ~ frac_s : frac_s_milli ( ) |
let pp_rfc3339_micro = pp_rfc3339 ~ frac_s : frac_s_micro ( ) |
let pp_rfc3339_nano = pp_rfc3339 ~ frac_s : frac_s_nano ( ) |
let to_rfc3339_milli = to_rfc3339 ~ frac_s : frac_s_milli |
let to_rfc3339_micro = to_rfc3339 ~ frac_s : frac_s_micro |
let to_rfc3339_nano = to_rfc3339 ~ frac_s : frac_s_nano |
let of_iso8601_exn = of_iso8601_exn ' of_iso8601 |
let to_sexp_string x = CCSexp . to_string ( To_sexp . sexp_of_date_time x ) |
let of_sexp = Of_sexp_utils . wrap_of_sexp Of_sexp . date_time_of_sexp |
let of_sexp_string = Of_sexp_utils . wrap_of_sexp_into_of_sexp_string Of_sexp . date_time_of_sexp |
let pp_sexp = Printers . wrap_to_sexp_into_pp_sexp To_sexp . sexp_of_date_time |
module ISO_week_date_time = struct include ISO_week_date_time ' let pp_iso8601 = ISO8601_printers . pp_iso_week_date_time let pp_iso8601_milli = pp_iso8601 ~ frac_s : frac_s_milli ( ) let pp_iso8601_micro = pp_iso8601 ~ frac_s : frac_s_micro ( ) let pp_iso8601_nano = pp_iso8601 ~ frac_s : frac_s_nano ( ) let to_iso8601... |
module ISO_ord_date_time = struct include ISO_ord_date_time ' let pp_iso8601 = ISO8601_printers . pp_iso_ord_date_time let pp_iso8601_milli = pp_iso8601 ~ frac_s : frac_s_milli ( ) let pp_iso8601_micro = pp_iso8601 ~ frac_s : frac_s_micro ( ) let pp_iso8601_nano = pp_iso8601 ~ frac_s : frac_s_nano ( ) let to_iso8601 = ... |
module Interval = struct type t = timestamp * timestamp let lt ( x1 , y1 ) ( x2 , y2 ) = Span . ( x1 < x2 || ( x1 = x2 && y1 < y2 ) ) let le x y = lt x y || x = y let gt x y = lt y x let ge x y = le y x let equal ( x1 , y1 ) ( x2 , y2 ) = Span . ( x1 = x2 && y1 = y2 ) let compare x y = if lt x y then - 1 else if x = y ... |
module Zoneless = struct include Zoneless ' let of_iso8601 = ISO8601_parsers . zoneless_of_str let of_iso8601_exn = of_iso8601_exn ' of_iso8601 let maybe_zoneless_of_iso8601 = ISO8601_parsers . maybe_zoneless_of_str let maybe_zoneless_of_iso8601_exn = of_iso8601_exn ' maybe_zoneless_of_iso8601 let to_sexp = To_sexp . s... |
module Time_zone_info = struct include Time_zone_info let of_sexp = Of_sexp_utils . wrap_of_sexp Of_sexp . tz_info_of_sexp let to_sexp = To_sexp . sexp_of_tz_info end |
module Utils = struct let ptime_span_of_span = Ptime_utils . ptime_span_of_span let ptime_of_timestamp = Ptime_utils . ptime_of_timestamp let span_of_ptime_span = Ptime_utils . span_of_ptime_span let timestamp_of_ptime = Ptime_utils . timestamp_of_ptime let day_count_of_year = day_count_of_year let day_count_of_month =... |
let local ( ) : string list = match Sys . getenv_opt " TZ " with | Some name -> [ name ] | None -> ( if CCIO . File . exists " / system / bin / getprop " then ( let ic = Unix . open_process_in " getprop " in let name = CCIO . read_all ic in close_in ic ; [ name ] ) else let try1 = List . fold_left ( fun tz file -> matc... |
type rsa_secret = { p : Z . t ; q : Z . t } |
type ciphertext = { nonce : Crypto_box . nonce ; payload : bytes } |
let unlocked_value_to_symmetric_key unlocked_value = let kdf_key = " Tezoskdftimelockv0 " in let to_hash = Z . to_string unlocked_value in let hash = Blake2B . ( to_bytes @@ hash_string ~ key : kdf_key [ to_hash ] ) in Crypto_box . Secretbox . unsafe_of_bytes hash |
let random_z size = Hacl . Rand . gen size |> Bytes . to_string |> Z . of_bits |
let random_prime_z size = let rec aux ( ) = let trial = random_z size in if Z . probab_prime trial 25 = 0 then aux ( ) else trial in aux ( ) |
let gen_rsa_keys ( ) = let size = size_modulus / ( 2 * 8 ) in let p = random_prime_z size in let q = random_prime_z size in ( Z . ( p * q ) , { p ; q } ) |
let gen_locked_value rsa_public = Z . erem ( random_z ( ( size_modulus / 8 ) + 16 ) ) rsa_public |
let hash_to_prime rsa_public ~ time value key = let personalization = Bytes . of_string " \ 032 " in let s = String . concat " \ xff \ x00 \ xff \ x00 \ xff \ x00 \ xff \ x00 " ( Int . to_string time :: List . map Z . to_bits [ rsa_public ; value ; key ] ) in let ( Hacl . Blake2b . Hash hash_result ) = Hacl . Blake2b .... |
let prove_without_secret rsa_public ~ time locked_value unlocked_value = let l = hash_to_prime rsa_public ~ time locked_value unlocked_value in let pow = Z . ( pow ( of_int 2 ) time / l ) in Z . powm locked_value pow rsa_public |
let prove_with_secret secret ~ time locked_value unlocked_value = let rsa_public = Z . ( secret . p * secret . q ) in let l = hash_to_prime rsa_public ~ time locked_value unlocked_value in let phi = Z . ( ( secret . p - one ) * ( secret . q - one ) ) in let pow = Z . ( pow ( of_int 2 ) time / l mod phi ) in Z . powm lo... |
let verify_time_lock rsa_public ~ time locked_value unlocked_value proof = let l = hash_to_prime rsa_public ~ time locked_value unlocked_value in let r = Z . ( powm ( of_int 2 ) ( Z . of_int time ) l ) in unlocked_value = Z . ( powm proof l rsa_public * powm locked_value r rsa_public mod rsa_public ) |
let unlock_with_secret secret ( ~ time : int ) ( locked_value : locked_value ) = let phi = Z . ( ( secret . p - one ) * ( secret . q - one ) ) in let e = Z . powm ( Z . of_int 2 ) ( Z . of_int time ) phi in Z . powm locked_value e Z . ( secret . p * secret . q ) |
let unlock_and_prove_with_secret secret ( ~ time : int ) ( locked_value : locked_value ) = let unlocked_value = unlock_with_secret secret ~ time locked_value in let pi = prove_with_secret secret ~ time locked_value unlocked_value in ( unlocked_value , pi ) |
let locked_value_to_symmetric_key_with_secret secret ( ~ time : int ) ( locked_value : locked_value ) : symmetric_key = unlocked_value_to_symmetric_key ( unlock_with_secret secret ~ time locked_value ) |
let unlock_and_prove_without_secret rsa_public ~ time locked_value = let rec aux time v = if time = 0 then v else aux Int . ( pred time ) Z . ( v * v mod rsa_public ) in let unlocked_value = aux time locked_value in let pi = prove_without_secret rsa_public ~ time locked_value unlocked_value in ( unlocked_value , pi ) |
let locked_value_to_symmetric_key_with_proof ( rsa_public : rsa_public ) ( ~ time : int ) locked_value unlocked_value proof = if verify_time_lock rsa_public ~ time locked_value unlocked_value proof then Some ( unlocked_value_to_symmetric_key unlocked_value ) else None |
let encrypt symmetric_key plaintext = let nonce = Crypto_box . random_nonce ( ) in { nonce ; payload = Crypto_box . Secretbox . secretbox symmetric_key plaintext nonce ; } |
let decrypt symmetric_key ciphertext = Crypto_box . Secretbox . secretbox_open symmetric_key ciphertext . payload ciphertext . nonce |
type chest_key = { unlocked_value : unlocked_value ; proof : time_lock_proof } |
type chest = { locked_value : locked_value ; rsa_public : rsa_public ; ciphertext : ciphertext ; } |
let chest_key_encoding = let open Data_encoding in def " timelock . chest_key " @@ conv ( fun chest_key -> ( chest_key . unlocked_value , chest_key . proof ) ) ( fun ( unlocked_value , proof ) -> { unlocked_value ; proof } ) ( obj2 ( req " unlocked_value " Data_encoding . n ) ( req " proof " Data_encoding . n ) ) |
let ciphertext_encoding = let open Data_encoding in def " timelock . ciphertext " @@ conv_with_guard ( fun ciphertext -> ( ciphertext . nonce , ciphertext . payload ) ) ( fun ( nonce , payload ) -> if Bytes . length payload <= Crypto_box . tag_length then Error " The ciphertext has a negative size " else Ok { nonce ; p... |
let min_rsa_modulus = Z . ( shift_left ( of_int 2 ) 2000 ) |
let chest_encoding = let open Data_encoding in def " timelock . chest " @@ conv_with_guard ( fun chest -> ( chest . locked_value , chest . rsa_public , chest . ciphertext ) ) ( fun ( locked_value , rsa_public , ciphertext ) -> if Z . Compare . ( locked_value < Z . zero || locked_value >= rsa_public ) then Error " locke... |
type opening_result = Correct of Bytes . t | Bogus_cipher | Bogus_opening |
let open_chest chest chest_key ~ time = if time < 0 then failwith " Timelock : trying to open with a negative time " else let sym_key_opt = locked_value_to_symmetric_key_with_proof chest . rsa_public ~ time chest . locked_value chest_key . unlocked_value chest_key . proof in match sym_key_opt with | None -> Bogus_openi... |
let create_chest_and_chest_key ~ payload ~ time = let ( rsa_public , rsa_secret ) = gen_rsa_keys ( ) in let locked_value = gen_locked_value rsa_public in let ( unlocked_value , proof ) = unlock_and_prove_with_secret rsa_secret ~ time locked_value in let sym_key = unlocked_value_to_symmetric_key unlocked_value in let ci... |
let create_chest_key chest ~ time = let ( unlocked_value , proof ) = unlock_and_prove_without_secret chest . rsa_public ~ time chest . locked_value in { unlocked_value ; proof } |
let get_plaintext_size chest = Bytes . length chest . ciphertext . payload - Crypto_box . tag_length |
let gen_random_bytes_unsafe size = Bytes . init size ( fun _ -> Char . chr ( Random . int 256 ) ) |
let gen_random_z_unsafe size = gen_random_bytes_unsafe size |> Bytes . to_string |> Z . of_bits |
let gen_random_prime_unsafe size = gen_random_z_unsafe size |> Z . nextprime |
let gen_rsa_keys_unsafe ( ) = let size = size_modulus / ( 2 * 8 ) in let p = gen_random_prime_unsafe size in let q = gen_random_prime_unsafe size in ( Z . ( p * q ) , { p ; q } ) |
let gen_locked_value_unsafe rsa_public = Z . erem ( gen_random_z_unsafe ( size_modulus / 8 ) ) rsa_public |
let encrypt_unsafe symmetric_key plaintext = let nonce = Data_encoding . Binary . of_bytes_exn Crypto_box . nonce_encoding ( gen_random_bytes_unsafe Crypto_box . nonce_size ) in { nonce ; payload = Crypto_box . Secretbox . secretbox symmetric_key plaintext nonce ; } |
let chest_sampler ~ rng_state ~ plaintext_size ~ time = Random . set_state rng_state ; let plaintext = gen_random_bytes_unsafe plaintext_size in let ( rsa_public , rsa_secret ) = gen_rsa_keys_unsafe ( ) in let locked_value = gen_locked_value_unsafe rsa_public in let ( unlocked_value , proof ) = unlock_and_prove_with_se... |
module Alarm_timeout = struct type t = unit let with_timeout ~ timeout ? on_timeout ~ do_ = let old_handler = ref Sys . Signal_default in let old_timeout = ref 0 in let on_timeout _sigalrm = match on_timeout with | None -> raise Timeout | Some f -> f ( ) ; raise Timeout in Utils . with_context ~ enter ( : fun ( ) -> ol... |
module Select_timeout = struct type t = { timeout : float ; } let create timeout = { timeout = Unix . gettimeofday ( ) . + timeout } let with_timeout ~ timeout ? on_timeout ~ do_ = let t = create ( float timeout ) in try do_ t with Timeout as exn -> match on_timeout with | None -> raise exn | Some ft -> ft ( ) ; raise ... |
module type S = sig type t val with_timeout : timeout : int -> ? on_timeout ( : unit -> unit ) -> do_ ( : t -> ' a ) -> ' a val check_timeout : t -> unit type in_channel val in_channel_of_descr : Unix . file_descr -> in_channel val descr_of_in_channel : in_channel -> Unix . file_descr val open_in : string -> in_channel... |
let select = ( module Select_timeout : S ) |
let alarm = ( module Alarm_timeout : S ) |
let read_connection ~ timeout ? on_timeout ~ reader sockaddr = with_timeout ~ timeout ? on_timeout ~ do_ ( : fun timeout -> let ( tic , oc ) = open_connection ~ timeout sockaddr in try reader timeout tic oc with exn -> close_out oc ; raise exn ) |
module type Time_intf = sig type t module Span : sig type t val to_time_ns_span : t -> Time_ns . Span . t val ( - ) : t -> t -> t end module Controller : sig type t end val now : Controller . t -> t val diff : t -> t -> Span . t end |
module Timeout_intf ( Time : Time_intf ) Time_intf = struct module type S = sig type ' a t val create : Time . Controller . t -> Time . Span . t -> f ( : Time . t -> ' a ) ' a -> ' a t val to_deferred : ' a t -> ' a Async_kernel . Deferred . t val peek : ' a t -> ' a option val cancel : Time . Controller . t -> ' a t -... |
module Make ( Time : Time_intf ) Time_intf : Timeout_intf ( Timeout_intfTime ) Timeout_intfTime . S = struct type ' a t = { deferred : ' a Deferred . t ; cancel : ' a -> unit ; start_time : Time . t ; span : Time . Span . t ; ctrl : Time . Controller . t } let create ctrl span ~ f : action = let open Deferred . Let_syn... |
module Core_time = Make ( struct include ( Core_kernel . Time : module type of Core_kernel . Time with module Span := Core_kernel . Time . Span and type underlying = float ) module Controller = struct type t = unit end module Span = struct include Core_kernel . Time . Span let to_time_ns_span = Fn . compose Core_kernel... |
module Core_time_ns = Make ( struct include ( Core_kernel . Time_ns : module type of Core_kernel . Time_ns with module Span := Core_kernel . Time_ns . Span ) module Controller = struct type t = unit end module Span = struct include Core_kernel . Time_ns . Span let to_time_ns_span = Fn . id end let diff x y = let x_ns =... |
let query_uri = let base_uri = Uri . of_string " http :// api . duckduckgo . com /? format = json " in fun query -> Uri . add_query_param base_uri ( " q " , [ query ] ) |
let get_definition_from_json json = match Yojson . Safe . from_string json with | ` Assoc kv_list -> begin match List . Assoc . find kv_list " Definition " with | None | Some ( ` String " " ) -> Or_error . error_string " No definition found " | Some s -> Ok ( Yojson . Safe . to_string s ) end | _ -> Or_error . error_st... |
let get_definition ~ timeout word = let get = Cohttp . Client . call ` GET ( query_uri word ) >>= fun ( _ , body ) -> Pipe . to_list body >>| fun strings -> get_definition_from_json ( String . concat strings ) in match timeout with | None -> get | Some timeout -> let timeout = Clock . after timeout in choose [ choice g... |
let run_one_search ~ timeout search_string = get_definition ~ timeout search_string >>| fun result -> printf " %- 10s : % s \ n " search_string ( match result with | Ok x -> x | Error err -> " { " ^ Error . to_string_hum err ^ " } " ) |
let run_many_searches ~ parallel ~ timeout search_strings = Deferred . List . iter search_strings ~ f ( : run_one_search ~ timeout ) ~ how ( : if parallel then ` Parallel else ` Sequential ) |
let ( ) = Command . async_basic ~ summary " : Retrieve definitions from duckduckgo search engine " Command . Spec . ( empty +> flag " - timeout " ( optional time_span ) ~ doc " : Whether to run queries in parallel " +> flag " - parallel " no_arg ~ doc " : Run queries in parallel " +> anon ( sequence ( " search term " %... |
type tkTimer = int = " camltk_add_timer " = " camltk_rem_timer " |
type t = tkTimer * cbid |
let add ~ ms ~ callback = if ! Protocol . debug then begin prerr_string " Timer . add " ; flush stderr ; end ; let id = new_function_id ( ) in if ! Protocol . debug then begin prerr_string " id " ; = prerr_cbid id ; flush stderr ; end ; let wrapped _ = clear_callback id ; callback ( ) in Hashtbl . add callback_naming_t... |
let set ~ ms ~ callback = ignore ( add ~ ms ~ callback ) ; ; |
let remove ( tkTimer , id ) = internal_rem_timer tkTimer ; clear_callback id |
type ' a range = ' a Range . range |
let resolve_exn ? search_using_tz time = match resolve ? search_using_tz time with | Ok s -> s | Error msg -> raise ( Resolution_error msg ) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.