In addition to what cmh and Loki have said, here are a few pet peeves of mine:
- Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.
Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.
So instead of
(char) foo
, usestatic_cast<char>(foo)
; yes, it’s long and ugly. That’s intentional to make the cast stand out. Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.
You are also converting quite a lot between chars and numbers by adding or subtracting
'A'
. Encapsulate this into a pair of functions, it makes the code cleaner.
So instead of (char) foo
, use static_cast<char>(foo)
; yes, it’s long and ugly. That’s intentional to make the cast stand out.
- Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.
You are also converting quite a lot between chars and numbers by adding or subtracting 'A'
. Encapsulate this into a pair of functions, it makes the code cleaner.
In addition to what cmh and Loki have said, here are a few pet peeves of mine:
- Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.
So instead of (char) foo
, use static_cast<char>(foo)
; yes, it’s long and ugly. That’s intentional to make the cast stand out.
- Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.
You are also converting quite a lot between chars and numbers by adding or subtracting 'A'
. Encapsulate this into a pair of functions, it makes the code cleaner.
In addition to what cmh and Loki have said, here are a few pet peeves of mine:
Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.
So instead of
(char) foo
, usestatic_cast<char>(foo)
; yes, it’s long and ugly. That’s intentional to make the cast stand out.Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.
You are also converting quite a lot between chars and numbers by adding or subtracting
'A'
. Encapsulate this into a pair of functions, it makes the code cleaner.
In addition to what cmh and Loki have said, here are a few pet peeves of mine:
- Ban C-style casts from your code-base. They are dangerous (they are an everything-goes cast which severely undermines the type system) and too innocuous. Casts should stand out.
So instead of (char) foo
, use static_cast<char>(foo)
; yes, it’s long and ugly. That’s intentional to make the cast stand out.
- Break the logic into smaller non-repeating blocks. With Loki’s amendments this is obsolete but in general look how similar your encrypt and decrypt functions are. You should strive to reduce this redundancy. If I remember my Vigenère correctly these functions are symmetrical and can be implemented by the same logic.
You are also converting quite a lot between chars and numbers by adding or subtracting 'A'
. Encapsulate this into a pair of functions, it makes the code cleaner.