Le vendredi 04 septembre 2015 à 17:42 -0700, Corey Moncure a écrit :
> Extremely new to Julia.  My background is in Python and C. 
> Working on implementing the Matasano crypto challenges in Julia to
> learn the ins and outs.  The implementations require heavy use of
> string conversions, casting, and byte comparisons.
> 
> Since Julia's built-in ascii() barfs on any byte that can't be
> represented in ASCII, it became useful to define a function that
> filters out all such bytes from a byte vector.
> 
> function ascii_filter(s::Array{Uint8})
>   if is_valid_ascii(s)
>     return s
I may be missing something, but don't you need to write this as:
return ascii(s)

>   end
>   filter!(x -> is_valid_ascii([x]), s)
>   @assert is_valid_ascii(s)
>   s = ascii(s)
>   @assert isa(s, ASCIIString)                     <-- assertion OK
>   return s
> end
> 
> 
> 
> The fact that is_valid_ascii() only has a method for vectors of
> bytes, and not a single byte, is a minor annoyance that is worked
> around by an anonymous function that wraps a Uint8 as a Vector{Uint8}
> of length 1.
> However, I cannot seem to make this return a variable of type
> ASCIIString, which is necessary for later use with uppercase(), etc. 
> 
> function detect_xor_encryption(cipher_text::Array{Uint8},
> keys::Vector, threshold::Int = 50)
>  {...}
>     clear_text = ascii_filter(repeating_xor(cipher_text, key))
>     @assert isa(clear_text, ASCIIString)          <-- assertion fails
>     s = score_candidate_language(clear_text, "english")
> {...}
> 
> 
> 
> function score_candidate_language(test_str::ASCIIString,
> language::String)
> {...}
> 
> 
> 
> At the time of assignment to clear_text, it seems the return value of
> ascii_filter() has fallen back to Array{Uint8}.  No amount of
> monkeying around in ascii_filter() could solve the problem.  I tried
> defining s::ASCIIString, and explicitly returning ascii(s) after the
> assert.  It seems that no matter what I do, I have to explicitly
> define the type of a variable as ::ASCIIString or wrap ascii() in the
> calling function every time I want to use ascii_filter() to build an
> ASCIIString and pass it to a function that takes an ASCIIString as an
> argument.
> 
> Is this intended?  Am I missing something obvious?
Would you be able to put together a reproducible example? That would
make it easier to spot what's going on.


Regards

Reply via email to