move again

This commit is contained in:
Florian Hoss 2022-05-30 21:14:32 +02:00
parent b2acdede89
commit 4da8357406
12 changed files with 3 additions and 3 deletions

View file

@ -0,0 +1,3 @@
module encrypt
go 1.18

View file

View file

@ -0,0 +1,40 @@
New Zealand's capital, Wellington, has been ranked one of the least affordable
cities in the world for buying a property. The picture is also grim for renters,
with a 12% rise in prices in the past year. That, along with increases in petrol
and food prices, has led many to consider moving to nearby Australia -
where they have the right to live and work.
Chris, a builder, his partner Harmony and their four daughters recently left
Wellington to start a new life in the Australian city of Brisbane.
Despite owning their home and earning reasonable salaries, they were still struggling.
"We have four kids, so it was expensive. We'd notice Australians saying you know the
cost of living is going up - but that was the cost five years ago in New Zealand,"
says Chris. Leaving New Zealand and the rest of her family was a
difficult decision for Harmony. But she says the move was necessary for the children.
"You can't make a living in New Zealand. There is no living. You just go backwards.
You don't get a choice if you want to live, you have to move, or
New Zealand has to change. I want a future for my children and there
is none in New Zealand," she says. The New Zealand government has tried
to increase some short-term measures like fuel subsidies and halving the cost
of public transport - but for many, it's not enough.
In Brescia, Italy, steel runs through the veins of the community.
In the past 15 years the industry has endured the financial crash and
the Covid-19 pandemic. Now, with the war in Ukraine and Covid lockdowns in China,
trade is being disrupted further. Mirella and Lucas met at a cast iron
foundry in Brescia. Their two steady wages are up against rising food, petrol
and energy costs. "With regard to electricity, we have recently suffered
like everyone else. Our bill has doubled - even though we are never at home",
says Mirella. "We are tightening our belts. Instead of saving a lot,
you'll save less," says Lucas. Orders at this cast iron foundry continue.
But a crucial source of raw materials from the south-eastern Ukrainian city of
Mariupol are in now short supply, after Russian troops occupied the region.
Mark Impraim owns a catering business in Ghana - one of the most expensive
countries to live in, in Africa. He shops for ingredients for one of his most
popular dishes -jollof rice - at a local market. But prices have doubled
in recent months. Mark looks at a bucket of tomatoes, dismayed at the price tag.
"[This box of tomatoes] used to be 20 cedis. Now it's going for 40," he says.
"I should double the price of the food I serve, but that would scare away customers.
I try to find a way around it by decreasing the quantity."
Among other rising costs eating into Mark's weekly budget is a supply
of drinking water. Sachets of water have increased in price twice in four months,
due to the devaluation of the cedi.
Water suppliers say passing the costs on to customers is unavoidable.

View file

@ -0,0 +1,95 @@
package main
import (
"flag"
"io/ioutil"
"log"
"os"
"regexp"
"strings"
"unicode"
)
const lettersInTheAlphabet = 26
const startUpperCase = 65
const endUpperCase = startUpperCase + lettersInTheAlphabet
const startLowerCase = 97
const endLowerCase = startLowerCase + lettersInTheAlphabet
type keyLetter struct {
upperCase string
position int32
}
func parseArguments() (string, string) {
var inputKey string
var inputFile string
flag.StringVar(&inputKey, "k", "", "Specify key word.")
flag.StringVar(&inputFile, "f", "", "Specify file to encrypt.")
flag.Parse()
return inputKey, inputFile
}
func readFile(relativePath string) string {
content, err := ioutil.ReadFile(relativePath)
if err != nil {
log.Fatalln(err)
}
return string(content)
}
func writeFile(relativePath string, message string) {
file, err := os.Create(relativePath)
if err != nil {
log.Fatalln(err)
}
defer file.Close()
file.WriteString(message)
}
func validateKeyWord(inputKey string) string {
reg, err := regexp.Compile("[^a-zA-Z]+")
if err != nil {
log.Fatalln(err)
}
processedString := reg.ReplaceAllString(inputKey, "")
return strings.ToUpper(processedString)
}
func initKeyWord(key string) []keyLetter {
var keyWord []keyLetter
for _, letter := range key {
keyWord = append(keyWord, keyLetter{
upperCase: string(letter),
position: letter - 'A',
})
}
return keyWord
}
func encryptMessage(keyWord []keyLetter, message string) string {
encrypted := ""
index := 0
for _, letter := range message {
if !unicode.IsLetter(letter) {
encrypted += string(letter)
} else {
keyWordIndex := index % len(keyWord)
newLetter := letter + keyWord[keyWordIndex].position
if (unicode.IsLower(letter) && newLetter >= endLowerCase) ||
(unicode.IsUpper(letter) && newLetter >= endUpperCase) {
newLetter -= lettersInTheAlphabet
}
encrypted += string(newLetter)
index += 1
}
}
return encrypted
}
func main() {
inputKey, inputFile := parseArguments()
message := readFile(inputFile)
keyWord := initKeyWord(validateKeyWord(inputKey))
writeFile("output.txt", encryptMessage(keyWord, message))
}

View file

@ -0,0 +1,17 @@
# Go parameters
GoCMD=go
GoBUILD=$(GoCMD) build
GoCLEAN=$(GoCMD) clean
GoTEST=$(GoCMD) test
GoMOD=$(GoCMD) mod
BINARY_NAME=tool
# To install GoLang please follow the installation instructions on https://go.dev/
all: build
build:
$(GoBUILD) -o $(BINARY_NAME) -v
clean:
$(GOCLEAN)
rm -f $(BINARY_NAME)
deps:
$(GoMOD) tidy

View file

@ -0,0 +1,40 @@
Spk Qmayhbv'k hldzbay, Dsddnyukwn, uhg twjy frvkrk cfw tq hym lrhgl skqcilaoss
uaytsj qn gos ogwwr wwr obmafl l diwpryhq. Lmp dzkthys ak fwgf orvt tgj wpbkmrf,
dwlz f 12% cwjm ia wfaujd we bhr wokl dpoi. Bhna, odgsr kzbh vuqjwfdsj qn clhjgq
lbu nobk djahpg, yis ylr essj hf koazwvww xcmqnt ac fwfcpp Iufafsdnl -
kymrr avwq mljv bhr ywyzy ec cqvr hbv otcy.
Tprvz, o tmnwrvz, hvz dsjyysi Paetcfq fyr kpevy tgmw oolohglfk jjnsebll ssxl
Bpzcqntacf lt dhrzt n uso dnqs zv tul Omkycocqaa jwlq tq Piqsohbw.
Vjddzbe bdbafl evvqr uvaw sso srznvuu jwfdceibyl gsdfcwva, tulm owwp gkqly zhjmlrzzvg.
"Jl vsnj qclz kvkg, kg ne kra ekwsfkngs. Nm'd avhauj Lijbrnswsfx dopqnt fcm cszk kpe
pvgl gk wwmqnt pg ygnyu lx - bha hzsy hoj bhr jckl ktjv genyg syt tb Emw Mlodsso,"
grgs Pofak. Qpomqnt Uso Rjlzrvd nur lzj csjb os osj xfxwcg wnz o
vakqwtclg ksuaxtce noe Oojetym. Sct fos ksdd hym mbcs osx ystmsfhfq xtc hym cupzvjjy.
"Mfc cnu'h espp o cqvvuu af Spk Qmayhbv. Lmpfv qs av zannyu. Pwu wbgl yt motswnyrk.
Qtf rfv't tlh s umzwtm is fcm ofyh kw lvcs, qgz somm tb tcnw, tc
Bve Zrhzsfi soj bo poofyj. T krvt n milmwp tfz ml jvadicse inq avwjj
tg ewnr pb Fwb Ksrtaak," gzw xlmj. Bhr Uso Rjlzrvd tvjwjsxseb hnz hjajo
hf qnpysskj dcdm suvfl-ljca dmafbfwk qtyv nurs gmtxtrzms nur zsqgweo tul qgky
zt gcbypq ljfyggwrg - iil xtc arvy, va'g fgy pbfcgu.
Pb Tjjdqzi, Ighzq, kypsc zuaz hzjtfuy bhr csafx zt kpe pvaemsthp.
Qn gos hsxe 15 mvirf avw asoijbrl ook wsoiimd gos xaslbtqay jfskm lbu
bhr Jcnai-19 aoelezpq. Fgb, hwkp tul ksj ny Ibzavus sfi Ncmqd yvqcvthbj qn Powfs,
ycoum if isafl owjzucasv xzchymr. Zpfwdql oel Lhjok eje ok i cnzh ajty
tfcnqym af Gcsjkin. Avwaw ekf atrhrq ofrsj irr bd syftbjb rvzwfy kzcu, xegycd
sso semrtf qgkyd. "Kzbh elusji ec vtepafaunem, nm hncs jwhpbkty fbtxwwpr
cqkr ljwjdzbv mlfl. Cmj gtzc paf kcmtqpr - vdea avgmls kv irr usnww lh ywmr",
zoqk Rtfvtln. "Ds sjj ewxptruwfy tff smlgz. Wfkypou wf fhjafl l zfb,
ybb'zd kfgs cmsf," zoqk Qfqra. Oeksjk fe hyqs phgl awzb wwuakfq utyhzvur.
Iil s hcitqay zcmjhp cw zaj tolwwtoca feva lzj dclbh-rhglwwy Ibzavuwsf hthp wf
Zhfamuzz rze vu bgo xscib shwddq, fqhvz Rhzgass effwpf vqumutsu bhr ysyaty.
Arzk Vtdjsnx cnvs n jolwwtbx jufpbwkx tb Xpaah - cfw tq hym mbzh wpupbjqvr
jcmfycwva tb swnw ny, we Ifepqs. Zj dvfxs svf aflcsuqeaag xgw zbv wf upg egxe
dfxuyhf vaxssj -royscx jnns - rb a yvqsd rlfbmt. Obh hjnnsj pail rgmgwsu
qn elqwfy xcebhf. Tojc qzcba ag h pmupph fn tbtolgjd, rzamnfsv sy evv xrvjs lsl.
"[Evza bbe cx ltxokwef] bgwv yz pv 20 keqpg. Fgb th'j oovuu xgw 40," ss jiyf.
"P gzgzwr uwuoss lzj afzke bm hzw kzcu Q sryjw, tze hyit jvidv xnoim ajhm umxecdmrf.
P hjq yz tzvd n doq swziel ig im vwhcsraian hzw vfoebigf."
Oegsr ckpee ywkasr qfatf lolasr webo Zhfc'k bpsbty obrywy tg r aucwzq
gk ofzvkvuu osypf. Jiculhk gk hokmr uhjw asnfvisrk wf hwtqv bwvjs af kzii uoaavk,
vzp hf bhr ksnsqfokqoa vt lzj nsuq.
Wnasj kzadcqeez gsq ulgjqnt avw utdhj wn gv qmkyzavzs vz ifsazwuibyl.