Skip to content

Commit a65ff28

Browse files
committed
added shift option to encoded text conversion
1 parent 3b2aa3d commit a65ff28

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

extras/fileformats/extras/testing/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ def ConvertibleToConverter(in_file: AbstractFile) -> ConvertibleToFile:
1616

1717
@converter # pyright: ignore[reportArgumentType]
1818
@python.define(outputs=["out_file"]) # type: ignore[misc]
19-
def EncodedFromTextConverter(in_file: TextFile) -> EncodedText:
19+
def EncodedFromTextConverter(in_file: TextFile, shift: int = 1) -> EncodedText:
2020
contents = in_file.read_text()
2121
# Encode by shifting ASCII codes forward by 1
22-
encoded_contents = "".join(chr(ord(c) + 1) for c in contents)
22+
encoded_contents = "".join(chr(ord(c) + shift) for c in contents)
2323
out_file = EncodedText.sample()
2424
out_file.write_text(encoded_contents)
2525
return out_file
2626

2727

2828
@converter # pyright: ignore[reportArgumentType]
2929
@python.define(outputs=["out_file"]) # type: ignore[misc]
30-
def EncodedToTextConverter(in_file: EncodedText) -> TextFile:
30+
def EncodedToTextConverter(in_file: EncodedText, shift: int = 1) -> TextFile:
3131
contents = in_file.read_text()
3232
# Decode by shifting ASCII codes back by 1
33-
decoded_contents = "".join(chr(ord(c) - 1) for c in contents)
33+
decoded_contents = "".join(chr(ord(c) - shift) for c in contents)
3434
out_file = TextFile.sample()
3535
out_file.write_text(decoded_contents)
3636
return out_file

0 commit comments

Comments
 (0)