Compare commits
2
Commits
0.5.0
..
79a498022e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
79a498022e | ||
|
|
5d56abbee9 |
@@ -28,6 +28,7 @@
|
||||
["-l" "--language CODE" "The string will be used to set a default symbols for a cipher."
|
||||
:validate [#(contains? language-options %) "Must be a code from the list: en, uk!!!"]]
|
||||
["-C" "--cracking" "Cracking the encrypted message."]
|
||||
["-O" "--output-file OUTPUT-FILE" "Save the program output to a file."]
|
||||
["-h" "--help"]])
|
||||
|
||||
(defn usage [options-summary]
|
||||
@@ -68,6 +69,12 @@
|
||||
(map-has-keys? options [:message, :message-file])
|
||||
{:exit-message (error-msg ["You can't use message and message-file options at the same time!!!"])}
|
||||
|
||||
(file/is-file-not-exists? (:message-file options))
|
||||
{:exit-message (error-msg ["Please, check the path to the message file!!!"])}
|
||||
|
||||
(file/is-file-exists? (:output-file options))
|
||||
{:exit-message (error-msg ["Please, choose another file!!! Overwriting was prevented!!!"])}
|
||||
|
||||
(and (map-has-keys? options [:cipher, :key])
|
||||
(or (contains? options :message)
|
||||
(contains? options :message-file))
|
||||
@@ -129,6 +136,18 @@
|
||||
(set-symbols)
|
||||
(load-and-set-option :message)))
|
||||
|
||||
(defn save-output
|
||||
"Save the output to a file"
|
||||
[output options]
|
||||
(let [file-path (:output-file options)]
|
||||
(file/write-file file-path output)))
|
||||
|
||||
(defn show-and-save-output
|
||||
"Print and save the output to a file if needed"
|
||||
[output options]
|
||||
(save-output output options)
|
||||
(println output))
|
||||
|
||||
(defn cracking-actions
|
||||
[options arguments action-type]
|
||||
(let [message (:message options)
|
||||
@@ -154,11 +173,13 @@
|
||||
(defn actions
|
||||
[options arguments action-type]
|
||||
(let [options (load-all-options options)]
|
||||
(println
|
||||
(->
|
||||
(cond
|
||||
(contains? #{:encrypt :decrypt} action-type)
|
||||
(crypt-actions options arguments action-type)
|
||||
|
||||
(= action-type :cracking)
|
||||
(cracking-actions options arguments action-type)))))
|
||||
(cracking-actions options arguments action-type))
|
||||
|
||||
(show-and-save-output options))))
|
||||
|
||||
|
||||
@@ -16,3 +16,6 @@
|
||||
(defn read-file [file-path]
|
||||
(slurp file-path))
|
||||
|
||||
(defn write-file [file-path content]
|
||||
(spit file-path content))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user