working example

This commit is contained in:
Kristian Krsnik 2023-08-24 18:40:32 +02:00
parent f83393b0a7
commit 46ce08588a
9 changed files with 48 additions and 21 deletions

1
.gitignore vendored
View File

@ -1 +1,2 @@
.direnv/
/result

View File

@ -1,15 +0,0 @@
def rot13(message):
subs = {'A': 'N', 'B': 'O', 'C': 'P', 'D': 'Q', 'E': 'R', 'F': 'S', 'G': 'T', 'H': 'U', 'I': 'V', 'J': 'W', 'K': 'X', 'L': 'Y', 'M': 'Z', 'N': 'A', 'O': 'B', 'P': 'C', 'Q': 'D', 'R': 'E', 'S': 'F', 'T': 'G', 'U': 'H', 'V': 'I', 'W': 'J', 'X': 'K', 'Y': 'L', 'Z': 'M',
'a': 'N', 'b': 'O', 'c': 'P', 'd': 'Q', 'e': 'R', 'f': 'S', 'g': 'T', 'h': 'U', 'i': 'V', 'j': 'W', 'k': 'X', 'l': 'Y', 'm': 'Z', 'n': 'A', 'o': 'B', 'p': 'C', 'q': 'D', 'r': 'E', 's': 'F', 't': 'G', 'u': 'H', 'v': 'I', 'w': 'J', 'x': 'K', 'y': 'L', 'z': 'M'}
return ''.join(list(map(
lambda x: subs[x] if x in subs else x,
message
)))
if __name__ == '__main__':
with open('./000-999/144/inputs/input') as file:
input = file.read()
print(rot13(input))

View File

@ -7,4 +7,4 @@ The folder name is the challenge id, as found in the URL (<https://play.picoctf.
Inside the folder there is an `inputs` subfolder which just includes all the files from the challenge description.
Executing `main.py` runs the challenge.
Executing `nix run .#CHALLENGE_ID` runs the challenge.

15
exercises/144/main.py Normal file
View File

@ -0,0 +1,15 @@
def rot13(message):
alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
subs = {char: alphabet[(i + 13) % 26] for i, char in enumerate(alphabet)}
return ''.join(list(map(
lambda x: subs[x] if x in subs else x,
message
)))
if __name__ == '__main__':
with open("./exercises/144/inputs/input") as file:
input = file.read()
print(rot13(input))

View File

@ -1,5 +1,5 @@
if __name__ == '__main__':
with open('./000-999/147/inputs/flag') as file:
with open('./exercises/147/inputs/flag') as file:
input = file.read()
print(input)

View File

@ -11,11 +11,37 @@
}: let
system = "x86_64-linux";
pkgs = nixpkgs.legacyPackages.${system};
exercises = builtins.attrNames (builtins.readDir ./exercises);
forAllExercises = nixpkgs.lib.genAttrs exercises;
in {
formatter.${system} = pkgs.alejandra;
devShells.${system}.default = pkgs.mkShellNoCC {
packages.${system} = forAllExercises (
exercise:
pkgs.writers.writePython3Bin "picoCTF_${exercise}" {
# libraries = with pkgs.python3.pkgs; [ requests ];
} "${builtins.readFile ./exercises/${exercise}/main.py}"
);
apps.${system} = forAllExercises (
exercise: {
type = "app";
program = "${self.packages.${system}.${exercise}}/bin/picoCTF_${exercise}";
}
);
devShells.${system} =
forAllExercises (
exercise:
pkgs.mkShellNoCC {
packages = with pkgs; [python3];
}
)
// {
default = pkgs.mkShellNoCC {
packages = with pkgs; [python3];
};
};
};
}