I have tried to implement the Hagelin C-35 machine. This machine has the historical significance of being the first mechanical pin-and-lug machine, as far as I know. It is thus a predecessor of M-209 and CX-52, among others. Nevertheless, the only source that I have been able to find that fully describes the encryption mechanism, aside from the patent itself, is an implementation in QBasic that I haven't been able to get running, but I have tried to replicate it in python.
import string
num2char = string.ascii_uppercase
char2num = dict(map(lambda c,n : (c,n), num2char, range(26)))
ps = [ [int(b) for b in list(pi)] for pi in [
'1100110001010101010110100',
'00100011100110111001101',
'101001101101010100100',
'1001101111010100111',
'00010101110100100',
]
] # Pins --- Part of the key
message = 'SECRETXMESSAGE'
aas = [1, 2, 4, 8, 10] # Lugs --- Fixed
cs = [7, 4, 18, 12, 1] # Initial positions --- Message key
ciphertext = []
for x in message:
cs = [(c + 1) % len(p) for (c, p) in zip(cs, ps)]
# The -1 would be +1 with the convention A=1, B=2...
z = -1 + sum([p[c] * a for (c, a, p) in zip(cs, aas, ps)])
ciphertext.append(num2char[(z-char2num[x]) % 26])
ciphertext = ''.join(ciphertext)
print(ciphertext)
It would be nice if someone that knows this machine could verify that the code is correct. The main doubt I have is about the -1. In the photos I cannot see the printing wheel to determine which letter gets encrypted to itself in the case of no active pins. The patent suggests that's letter X, in which case the -1 would have to be replaced by -6. However it is not made clear in the patent, and the QBasic code does not seem to use that number.
Note that in writing the numbers in cs I'm using the convention A=0, B=1... Z=24 skipping the letter w.