@@ -19,15 +19,15 @@ namespace local_rsa
1919
2020 auto ascii_to_hex (const std::string& input) -> std::string
2121 {
22- static constexpr char hex[] = " 0123456789abcdef" ; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
22+ constexpr char hex[] = " 0123456789abcdef" ; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
2323
2424 std::string out;
2525 out.reserve (input.size () * 2U );
2626
2727 for (const char c : input)
2828 {
29- out.push_back (hex[static_cast <std::size_t >(c) >> 4U ]);
30- out.push_back (hex[static_cast <std::size_t >(c) & 0x0FU ]);
29+ out.push_back (hex[static_cast <std::size_t >(c) >> 4U ]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index)
30+ out.push_back (hex[static_cast <std::size_t >(c) & 0x0FU ]); // NOLINT(cppcoreguidelines-pro-bounds-constant-array-index,cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
3131 }
3232
3333 return out;
@@ -37,15 +37,15 @@ namespace local_rsa
3737 {
3838 char c_result { };
3939
40- if (c >= ' 0' && c <= ' 9' ) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
40+ if (( c >= ' 0' ) && ( c <= ' 9' )) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
4141 {
4242 c_result = static_cast <char >(c - ' 0' ); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
4343 }
44- else if (c >= ' a' && c <= ' f' ) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
44+ else if (( c >= ' a' ) && ( c <= ' f' )) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
4545 {
4646 c_result = static_cast <char >((c - ' a' ) + char { 10 }); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
4747 }
48- else if (c >= ' A' && c <= ' F' ) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
48+ else if (( c >= ' A' ) && ( c <= ' F' )) // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
4949 {
5050 c_result = static_cast <char >((c - ' A' ) + char { 10 }); // NOLINT(cppcoreguidelines-avoid-magic-numbers,readability-magic-numbers)
5151 }
@@ -91,8 +91,8 @@ namespace local_rsa
9191 allocator_type>;
9292 #else
9393 using my_uintwide_t = ::math::wide_integer::uintwide_t <static_cast <math::wide_integer::size_t >(bit_count),
94- LimbType,
95- allocator_type>;
94+ LimbType,
95+ allocator_type>;
9696 #endif
9797
9898 using limb_type = typename my_uintwide_t ::limb_type;
@@ -152,9 +152,13 @@ namespace local_rsa
152152
153153 auto encrypt (const std::string& str_message) -> my_uintwide_t
154154 {
155- const my_uintwide_t message { (" 0x" + detail::ascii_to_hex (str_message)).c_str () };
156-
157- return powm (message, public_key.r , public_key.m );
155+ return
156+ powm
157+ (
158+ my_uintwide_t { (" 0x" + detail::ascii_to_hex (str_message)).c_str () },
159+ public_key.r ,
160+ public_key.m
161+ );
158162 }
159163
160164 private:
@@ -168,7 +172,7 @@ namespace local_rsa
168172
169173 auto decrypt (const my_uintwide_t & cry_in) -> std::string
170174 {
171- const my_uintwide_t tmp = powm (cry_in, private_key.s , private_key.q * private_key.p );
175+ const my_uintwide_t tmp { powm (cry_in, private_key.s , private_key.q * private_key.p ) } ;
172176
173177 std::stringstream strm { };
174178
@@ -314,7 +318,7 @@ namespace local_rsa
314318
315319 static auto make_positive (const my_uintwide_t & number, const my_uintwide_t & modulus) -> my_uintwide_t // NOLINT(bugprone-easily-swappable-parameters)
316320 {
317- my_uintwide_t tmp = number;
321+ my_uintwide_t tmp { number } ;
318322
319323 while (is_neg (tmp)) // NOLINT(altera-id-dependent-backward-branch)
320324 {
@@ -460,10 +464,10 @@ auto ::math::wide_integer::example012_rsa_crypto() -> bool
460464 // Select "abc" as the sample string to encrypt.
461465 const std::string in_str { " Hello wide-integer RSA" };
462466
463- const rsa_type::my_uintwide_t cry_out { rsa.encrypt (in_str) };
464- const std::string res_str { rsa.decrypt (cry_out ) };
467+ const rsa_type::my_uintwide_t cipher_text { rsa.encrypt (in_str) };
468+ const std::string str_recover { rsa.decrypt (cipher_text ) };
465469
466- result_is_ok = ((res_str == in_str) && result_is_ok);
470+ result_is_ok = ((str_recover == in_str) && result_is_ok);
467471
468472 return result_is_ok;
469473}
0 commit comments