Skip to content

Commit

Permalink
Merge pull request #23 from Wikunia/plots-bounds
Browse files Browse the repository at this point in the history
Updated Plots and Colors dependency
  • Loading branch information
Wikunia authored Dec 20, 2020
2 parents 3475233 + 46a8898 commit 1c73d7c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 49 deletions.
69 changes: 49 additions & 20 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,57 @@
name: Run tests

on: [push, pull_request]

name: CI
on:
- push
- pull_request
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
julia-version: [1.0.4, 1.3.0]
julia-arch: [x64]
os: [ubuntu-latest, windows-latest, macOS-latest]

version:
- '1.0'
- '1.5'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- uses: actions/[email protected]
- name: "Set up Julia"
uses: julia-actions/[email protected]
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.julia-version }}
arch: ${{ matrix.julia-arch }}
- name: "Build package"
uses: julia-actions/julia-buildpkg@master
- name: "Run tests"
uses: julia-actions/julia-runtest@master
- name: "CodeCov"
uses: julia-actions/julia-uploadcodecov@master
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v1
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
docs:
name: Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
with:
version: '1'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.instantiate()'
- name: Build and deploy
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} # For authentication with SSH deploy key
run: julia --project=docs/ docs/make.jl
8 changes: 4 additions & 4 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
name = "Enigma"
uuid = "68071ed3-b3ed-4442-ae89-ae359c4518d1"
authors = ["Ole Kröger <[email protected]>"]
version = "0.1.0"
version = "0.2.0"

[deps]
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

[compat]
julia = "1"
Colors = "^0.11.2"
Colors = "^0.11.2, ^0.12"
Plots = "^1"
Documenter = "^0.24.5"
Plots = "^0.29.0"
julia = "1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
12 changes: 6 additions & 6 deletions src/Enigma.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const possible_ukw = [
]

const possible_rotors = [
Dict(:name => "I",
Dict(:name => "I",
:mapping => [05, 11, 13, 06, 12, 07, 04, 17, 22, 26, 14, 20, 15, 23, 25, 08, 24, 21, 19, 16, 01, 09, 02, 18, 03, 10],
:rotation_point => 18),
Dict(:name => "II",
Expand Down Expand Up @@ -74,7 +74,7 @@ end
Creates an EnigmaMachine with the following setting:\n
Rotor ids from left to right: r1, r2, r3\n
r1=1 would be setting the left most rotor to the rotor I\n
The reflector ( = ukw = Umkehrwalze) is 1,2,3 as well and correspond to the ukws A,B and C\n
The reflector ( = ukw = Umkehrwalze) is 1,2,3 as well and correspond to the ukws A,B and C\n
Additionally the rotor positions can be set using p1,p2 and p3 for the three rotors\n
Return the created EnigmaMachine
"""
Expand Down Expand Up @@ -148,8 +148,8 @@ function set_plugboard!(enigma::EnigmaMachine, setting::String)
enigma.plugboard[i] = i
end
setting == "" && return
parts = split(setting, " ")
for part in parts
parts = split(setting, " ")
for part in parts
from_letter, to_letter = part[1], part[2]
from = Int(uppercase(from_letter))-64
to = Int(uppercase(to_letter))-64
Expand Down Expand Up @@ -224,7 +224,7 @@ end
If all chars in the string are uppercase letters (so no spaces) then `input_validation` can be set to false for a bit speed up.\n
The default output consists of blocks of five letters. If you don't want the spaces you can set `output_style=false`.\n
Return the string encoded with the enigma.
Return the string encoded with the enigma.
"""
function encode!(enigma::EnigmaMachine, s::String; input_validation=true, output_style=:enigma)
if input_validation
Expand Down Expand Up @@ -259,4 +259,4 @@ function enigma_styled_text(text::String)
end

export EnigmaMachine, encode!, decode!, set_rotors!, set_rotor_positions!, set_ukw!, set_plugboard!, enigma_styled_text
end
end
38 changes: 19 additions & 19 deletions src/EnigmaVis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,25 @@ function plot_ukw(plt, ukw)

plot!(plt, [order*width+2.5], [27], annotation=(order*width+2.5, 27, "UKW $(ukw.name)"))
plot!(plt, rectangle(5,26, order*width, 0), color=:gray)

for i=1:26
letter = Char(i+64)
plot!(plt, rectangle(1,1, order*width-1, i-1), color=:darkgray)
plot!(plt, [order*width-1], [i-1], annotation=(order*width-0.5, i-0.5, letter))

plot!(plt, rectangle(1,1, order*width+5, i-1), color=:darkgray)
plot!(plt, [order*width+5], [i-1], annotation=(order*width+5.5, i-0.5, letter))

# left lower/upper -
plot!(plt, [order*width,order*width+0.3], [i-0.6, i-0.6], color=:black)
plot!(plt, [order*width,order*width+0.3], [i-0.3, i-0.3], color=:black)

# right lower -
plot!(plt, [order*width+4.7,order*width+5], [i-0.6, i-0.6], color=:black)

# right upper -
plot!(plt, [order*width+4.7,order*width+5], [i-0.3, i-0.3], color=:black)

y_pos_from = i-0.6
y_pos_to = ukw.mapping[i]-0.6
# right ro left
Expand All @@ -87,7 +87,7 @@ function plot_ukw(plt, ukw)
end

function update_plugboard_plot(plt, plugboard; right_idx=nothing, left_idx=nothing, connecting=false, connected=false)
@assert right_idx !== nothing || left_idx !== nothing
@assert right_idx !== nothing || left_idx !== nothing
order = 4
width = 7.5

Expand All @@ -107,13 +107,13 @@ function update_plugboard_plot(plt, plugboard; right_idx=nothing, left_idx=nothi
connected && (connecting = true)
for i in (connected_to, right_idx)
letter = Char(i+64)

# left box and letter
if (connected || finished) && connected_to == i
plot!(plt, rectangle(1,1, order*width-1, i-1), color=:yellow)
plot!(plt, [order*width-1], [i-1], annotation=(order*width-0.5, i-0.5, letter))
end
# right box and letter
# right box and letter
if right_idx == i && finished && connected
plot!(plt, rectangle(1,1, order*width+5, i-1), color=:green)
plot!(plt, [order*width+5], [i-1], annotation=(order*width+5.5, i-0.5, letter))
Expand All @@ -133,7 +133,7 @@ function update_plugboard_plot(plt, plugboard; right_idx=nothing, left_idx=nothi
plot!(plt, [order*width,order*width+0.3], [i-0.5, i-0.5], color=:yellow)
end
end
return plt
return plt
end

function plot_plugboard(plt, plugboard)
Expand All @@ -147,22 +147,22 @@ function plot_plugboard(plt, plugboard)
letter = Char(i+64)
plot!(plt, rectangle(1,1, order*width-1, i-1), color=:darkgray)
plot!(plt, [order*width-1], [i-1], annotation=(order*width-0.5, i-0.5, letter))

plot!(plt, rectangle(1,1, order*width+5, i-1), color=:darkgray)
plot!(plt, [order*width+5], [i-1], annotation=(order*width+5.5, i-0.5, letter))

y_pos_from = i-0.5
y_pos_to = plugboard[i]-0.5
plot!(plt, [order*width+4.7, order*width+0.3], [y_pos_from, y_pos_to], color=:black)
plot!(plt, [order*width+4.7,order*width+5], [i-0.5, i-0.5], color=:black)

plot!(plt, [order*width,order*width+0.3], [i-0.5, i-0.5], color=:black)
end
return plt
end

function update_rotor_plot(plt::Plots.Plot, rotor::Rotor; right_idx = nothing, left_idx = nothing, connecting=false, connected=false)
@assert right_idx !== nothing || left_idx !== nothing
@assert right_idx !== nothing || left_idx !== nothing

order = rotor.order
width = 7.5
Expand Down Expand Up @@ -197,12 +197,12 @@ function update_rotor_plot(plt::Plots.Plot, rotor::Rotor; right_idx = nothing, l
plot!(plt, [order*width+5], [i-1], annotation=(order*width+5.5, i-0.5, letter))
end

# left side small -
# left side small -
if left_idx == i
plot!(plt, [order*width,order*width+0.3], [i-0.5, i-0.5], color=:yellow)
end

# left side small -
# left side small -
if right_idx == i
plot!(plt, [order*width+4.7,order*width+5], [i-0.5, i-0.5], color=:yellow)
end
Expand Down Expand Up @@ -242,10 +242,10 @@ function plot_rotor(plt::Plots.Plot, rotor::Rotor)
plot!(plt, rectangle(1,1, order*width+5, i-1), color=:darkgray)
plot!(plt, [order*width+5], [i-1], annotation=(order*width+5.5, i-0.5, letter))

# left side small -
# left side small -
plot!(plt, [order*width,order*width+0.3], [i-0.5, i-0.5], color=:black)

# left side small -
# left side small -
plot!(plt, [order*width+4.7,order*width+5], [i-0.5, i-0.5], color=:black)
end
# plot connections
Expand Down Expand Up @@ -286,7 +286,7 @@ function get_enigma_decode_plots!(enigma::EnigmaMachine, letter::Char; pngs=fals
update_plugboard_plot(plt, enigma.plugboard; right_idx=letter_idx, connected=true)
push!(plts, deepcopy(plt))
pngs && png(plt, "visualizations/plugboard_in")

plugboard_out_idx = enigma.plugboard[letter_idx]
right_idx = plugboard_out_idx
for r=3:-1:1
Expand Down Expand Up @@ -331,7 +331,7 @@ end
function animate_plots(plts::Vector{Plots.Plot}, fname::String; end_extra=5)
anim = Animation()
for plt in plts
plot(plt)
plot(plt)
frame(anim)
end
for i=1:end_extra
Expand All @@ -341,4 +341,4 @@ function animate_plots(plts::Vector{Plots.Plot}, fname::String; end_extra=5)
gif(anim, "$fname.gif", fps=4)
end

export get_enigma_plot, get_enigma_decode_plots!, animate_plots
export get_enigma_plot, get_enigma_decode_plots!, animate_plots

0 comments on commit 1c73d7c

Please sign in to comment.