Skip to content

Commit

Permalink
translating; cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
yurichev committed Sep 10, 2020
1 parent 1299396 commit 46bed43
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 79 deletions.
33 changes: 0 additions & 33 deletions advanced/800_win16/main.tex

This file was deleted.

27 changes: 27 additions & 0 deletions advanced/800_win16/main_EN.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\mysection{Windows 16-bit}
\myindex{Windows!Windows 3.x}

16-bit Windows programs are rare nowadays, but can be used in the cases of retrocomputing
or dongle hacking (\myref{dongles}).

16-bit Windows versions were up to 3.11.
95/98/ME also support 16-bit code, as well as the 32-bit versions of the \gls{Windows NT} line.
The 64-bit versions of \gls{Windows NT} line do not support 16-bit executable code at all.

The code resembles MS-DOS's one.

Executable files are of type NE-type (so-called \q{new executable}).

All examples considered here were compiled by the OpenWatcom 1.9 compiler, using these switches:

\begin{lstlisting}
wcl.exe -i=C:/WATCOM/h/win/ -s -os -bt=windows -bcl=windows example.c
\end{lstlisting}

\input{\CURPATH/ex1.tex}
\input{\CURPATH/ex2.tex}
\input{\CURPATH/ex3.tex}
\input{\CURPATH/ex4.tex}
\input{\CURPATH/ex5.tex}
\input{\CURPATH/ex6_EN.tex}

27 changes: 27 additions & 0 deletions advanced/800_win16/main_RU.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
\mysection{Windows 16-bit}
\myindex{Windows!Windows 3.x}

16-битные программы под Windows в наше время редки, хотя иногда можно поработать с ними, в смысле ретрокомпьютинга,
либо которые защищенные донглами (\myref{dongles}).

16-битные версии Windows были вплоть до 3.11.
95/98/ME также поддерживает 16-битный код, как и все 32-битные OS линейки \gls{Windows NT}.
64-битные версии \gls{Windows NT} не поддерживают 16-битный код вообще.

Код напоминает тот что под MS-DOS.

Исполняемые файлы имеют NE-тип (так называемый \q{new executable}).

Все рассмотренные здесь примеры скомпилированы компилятором OpenWatcom 1.9 используя эти опции:

\begin{lstlisting}
wcl.exe -i=C:/WATCOM/h/win/ -s -os -bt=windows -bcl=windows example.c
\end{lstlisting}

\input{\CURPATH/ex1.tex}
\input{\CURPATH/ex2.tex}
\input{\CURPATH/ex3.tex}
\input{\CURPATH/ex4.tex}
\input{\CURPATH/ex5.tex}
\input{\CURPATH/ex6_RU.tex}

106 changes: 79 additions & 27 deletions advanced/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -17,84 +17,134 @@
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/050_strstr}
\EN{\input{\CURPATH/main_EN}}\DE{\input{\CURPATH/main_DE}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\DE{\input{\CURPATH/main_DE}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/060_qsort_redux}
\EN{\input{\CURPATH/main_EN}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/100_fahrenheit}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/102_fib}
\EN{\input{\CURPATH/main}}\RU{\input{\CURPATH/main}}\FR{\input{\CURPATH/main}}
\EN{\input{\CURPATH/main}}
\RU{\input{\CURPATH/main}}
\FR{\input{\CURPATH/main}}

\renewcommand{\CURPATH}{advanced/110_CRC32}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/111_netmask}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/115_loop_iterators}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/117_duff_device}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/120_division_by_mult}
\EN{\input{\CURPATH/main}}\RU{\input{\CURPATH/main}}\FR{\input{\CURPATH/main}}
\EN{\input{\CURPATH/main}}
\RU{\input{\CURPATH/main}}
\FR{\input{\CURPATH/main}}

\renewcommand{\CURPATH}{advanced/125_atoi}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/127_inline_function}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/130_C99_restrict}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/135_abs_branchless}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/170_variadic_functions}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/200_string_trim}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/250_toupper}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/310_obfuscation}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/350_cpp}
\EN{\input{\CURPATH/main}}\RU{\input{\CURPATH/main}}\FR{\input{\CURPATH/main}}
\EN{\input{\CURPATH/main}}
\RU{\input{\CURPATH/main}}
\FR{\input{\CURPATH/main}}

\renewcommand{\CURPATH}{advanced/370_neg_arrays}
\EN{\input{\CURPATH/main_EN}}\RU{\input{\CURPATH/main_RU}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

% too heavy. I never liked it... maybe I'll change my mind
%\renewcommand{\CURPATH}{advanced/380_FAT12}
%\EN{\input{\CURPATH/main_EN}}\FR{\input{\CURPATH/main_FR}}
%\EN{\input{\CURPATH/main_EN}}
%\FR{\input{\CURPATH/main_FR}}

\EN{\input{advanced/450_more_ptrs/main_EN}}
\RU{\input{advanced/450_more_ptrs/main_RU}}
\FR{\input{advanced/450_more_ptrs/main_FR}}

\EN{\input{advanced/500_loop_optimizations/main_EN}}\RU{\input{advanced/500_loop_optimizations/main_RU}}\FR{\input{advanced/500_loop_optimizations/main_FR}}
\EN{\input{advanced/500_loop_optimizations/main_EN}}
\RU{\input{advanced/500_loop_optimizations/main_RU}}
\FR{\input{advanced/500_loop_optimizations/main_FR}}

\EN{\input{advanced/550_more_structs/main_EN}}\RU{\input{advanced/550_more_structs/main_RU}}\FR{\input{advanced/550_more_structs/main_FR}}
\EN{\input{advanced/550_more_structs/main_EN}}
\RU{\input{advanced/550_more_structs/main_RU}}
\FR{\input{advanced/550_more_structs/main_FR}}

\EN{\input{advanced/600_memmove/main_EN}}\RU{\input{advanced/600_memmove/main_RU}}\FR{\input{advanced/600_memmove/main_FR}}
\EN{\input{advanced/600_memmove/main_EN}}
\RU{\input{advanced/600_memmove/main_RU}}
\FR{\input{advanced/600_memmove/main_FR}}

\EN{\input{advanced/625_setjmp/main_EN}}\RU{\input{advanced/625_setjmp/main_RU}}\FR{\input{advanced/625_setjmp/main_FR}}
\EN{\input{advanced/625_setjmp/main_EN}}
\RU{\input{advanced/625_setjmp/main_RU}}
\FR{\input{advanced/625_setjmp/main_FR}}

\EN{\input{advanced/650_stack/main}}\RU{\input{advanced/650_stack/main}}\FR{\input{advanced/650_stack/main}}
\EN{\input{advanced/650_stack/main}}
\RU{\input{advanced/650_stack/main}}
\FR{\input{advanced/650_stack/main}}

\EN{\input{advanced/700_openmp/main_EN}}\RU{\input{advanced/700_openmp/main_RU}}\FR{\input{advanced/700_openmp/main_FR}}
\EN{\input{advanced/700_openmp/main_EN}}
\RU{\input{advanced/700_openmp/main_RU}}
\FR{\input{advanced/700_openmp/main_FR}}

\EN{\input{advanced/710_signed_division_using_shifts/main_EN}}%
\EN{\input{advanced/710_signed_division_using_shifts/main_EN}}
\FR{\input{advanced/710_signed_division_using_shifts/main_FR}}

\EN{\input{advanced/750_heisenbug/main_EN}}
Expand All @@ -112,5 +162,7 @@
\FR{\input{\CURPATH/main_FR}}

\renewcommand{\CURPATH}{advanced/800_win16}
\EN{\input{\CURPATH/main}}\RU{\input{\CURPATH/main}}\FR{\input{\CURPATH/main_FR}}
\EN{\input{\CURPATH/main_EN}}
\RU{\input{\CURPATH/main_RU}}
\FR{\input{\CURPATH/main_FR}}

1 change: 1 addition & 0 deletions ff/XOR/main.tex
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
\EN{\input{ff/XOR/simplest/main_EN}}
\FR{\input{ff/XOR/simplest/main_FR}}
\DE{\input{ff/XOR/simplest/main_DE}}
\RU{\input{ff/XOR/simplest/main_RU}}

\EN{\input{ff/XOR/ng/main_EN}}
\RU{\input{ff/XOR/ng/main_RU}}
Expand Down
9 changes: 3 additions & 6 deletions ff/XOR/simplest/main_DE.tex
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ \subsection{Einfachste XOR-Verschlüsselung überhaupt}

Ich habe einmal eine Software gesehen, bei der alle Debugging-Ausgaben mit XOR mit dem Wert 3
verschlüsselt wurden. Mit anderen Worten, die beiden niedrigsten Bits aller Buchstaben wurden invertiert.
% to be synced: In other words, two lowest bits of each character has been flipped.

``Hello, world'' wurde zu ``Kfool/\#tlqog'':

\begin{lstlisting}
\begin{lstlisting}[caption=Python,style=custompy]
#!/usr/bin/python

msg="Hello, world!"
Expand Down Expand Up @@ -41,11 +42,7 @@ \subsection{Einfachste XOR-Verschlüsselung überhaupt}
print "".join(map(lambda x: chr(ord(x)^3), msg))
\end{lstlisting}

Ergebnis:
% FIXME \verb -- relevant comment for German?
\begin{lstlisting}
CBA@GFEDKJIHONML
\end{lstlisting}
Ergebnis: \verb|CBA@GFEDKJIHONML|.

Es sieht so aus als würden die Zeichen ``@'' und ``C'' sowie ``B'' und ``A'' vertauscht werden.

Expand Down
10 changes: 3 additions & 7 deletions ff/XOR/simplest/main_EN.tex
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
\subsection{Simplest ever XOR encryption}

I once saw a software where all debugging messages has been encrypted using XOR by value of 3.
In other words, two lowest bits of all characters has been flipped.
In other words, two lowest bits of each character has been flipped.

``Hello, world'' would become ``Kfool/\#tlqog'':

\begin{lstlisting}
\begin{lstlisting}[caption=Python,style=custompy]
#!/usr/bin/python

msg="Hello, world!"
Expand Down Expand Up @@ -39,11 +39,7 @@ \subsection{Simplest ever XOR encryption}
print "".join(map(lambda x: chr(ord(x)^3), msg))
\end{lstlisting}

Result:
% FIXME \verb
\begin{lstlisting}
CBA@GFEDKJIHONML
\end{lstlisting}
Result: \verb|CBA@GFEDKJIHONML|.

It's like ``@'' and ``C'' characters has been swapped, and so are ``B'' and ``a''.

Expand Down
9 changes: 3 additions & 6 deletions ff/XOR/simplest/main_FR.tex
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ \subsection{Chiffrement XOR le plus simple}
J'ai vu une fois un logiciel où tous les messages de débogage étaient chiffrés en
utilisant XOR avec une valeur de 3.
Autrement dit, les deux bits les plus bas de chaque caractères étaient inversés.
% to be synced: In other words, two lowest bits of each character has been flipped.

``Hello, world'' devenait ``Kfool/\#tlqog'':

\begin{lstlisting}
\begin{lstlisting}[caption=Python,style=custompy]
#!/usr/bin/python

msg="Hello, world!"
Expand Down Expand Up @@ -43,11 +44,7 @@ \subsection{Chiffrement XOR le plus simple}
print "".join(map(lambda x: chr(ord(x)^3), msg))
\end{lstlisting}

Résultat:
% FIXME \verb
\begin{lstlisting}
CBA@GFEDKJIHONML
\end{lstlisting}
Résultat: \verb|CBA@GFEDKJIHONML|.

C'est comme si les caractères ``@'' et ``C'' avaient été échangés, ainsi que ``B''
et ``a''.
Expand Down
49 changes: 49 additions & 0 deletions ff/XOR/simplest/main_RU.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
\subsection{Простейшее XOR-шифрование}

Однажды я видел ПО, где все отладочные сообщения были зашифрованы используя XOR со значением 3.
Иными словами, 2 младших бита каждого символа были переключены.

``Hello, world'' становилось ``Kfool/\#tlqog'':

\begin{lstlisting}[caption=Python,style=custompy]
#!/usr/bin/python

msg="Hello, world!"

print "".join(map(lambda x: chr(ord(x)^3), msg))
\end{lstlisting}

Это интересное шифрование (или даже обфускация), потому что оно имеет два важных свойства:
1) одна ф-ция для шифрования/дешифрования, просто вызовите её еще раз;
2) символы на выходе печатаемые, так что вся строка может быть использована в исходном коде без специальных (\text{escaping}) символов.

Второе свойство использует тот факт что все печатаемые символы расположены в рядах: 0x2x-0x7x, и когда вы меняете
два младших бита, символ \emph{перемещается} на 1 или 3 символа влево или вправо, но никогда не \emph{перемещается} в другой
(может быть, непечатаемый) ряд:

\begin{figure}[H]
\centering
\includegraphics[width=0.8\textwidth]{ascii_clean.png}
\caption{7-битная \ac{ASCII}-таблица в Emacs}
\end{figure}

\dots с единственным исключением символа 0x7F.

Например, давайте \emph{зашифруем} символы в пределах A-Z:

\begin{lstlisting}
#!/usr/bin/python

msg="@ABCDEFGHIJKLMNO"

print "".join(map(lambda x: chr(ord(x)^3), msg))
\end{lstlisting}

Результат: \verb|CBA@GFEDKJIHONML|.

Это как если символы ``@'' и ``C'' были поменены местами, и так же и ``B'' и ``a''.

Так или иначе, это интересный пример использующий свойства XOR, нежели шифрование:
тот самый эффект \emph{сохранения печатаемости} может быть достигнут переключая любой из младших 4-х бит,
в любой последовательности.

0 comments on commit 46bed43

Please sign in to comment.