Repository: TheAlgorithms/Python

Issue:
`maths/binary_exponentiation_2.py` needs to be renamed
### Repository commit

ef8df1451b7e9296cd3706cbfd0900f33acc4bb9

### Python version (python --version)

Python 3.11.5

### Dependencies version (pip freeze)

<details>
<summary>Dependency versions</summary>

```
beautifulsoup4==4.12.2
black==23.3.0
bs4==0.0.1
certifi==2023.5.7
cffi==1.15.1
cfgv==3.3.1
charset-normalizer==3.1.0
click==8.1.3
contourpy==1.1.0
cryptography==41.0.1
cycler==0.11.0
dill==0.3.6
distlib==0.3.6
fake-useragent==1.2.1
filelock==3.12.2
fonttools==4.40.0
identify==2.5.24
idna==3.4
joblib==1.3.1
kiwisolver==1.4.4
lxml-stubs==0.4.0
matplotlib==3.7.1
mpmath==1.3.0
mypy==1.4.0
mypy-extensions==1.0.0
networkx==3.1
nodeenv==1.8.0
ntlm-auth==1.5.0
numpy==1.26.0
packaging==23.1
pandas==2.0.3
pandas-stubs==2.1.1.230928
pathspec==0.11.1
pbr==5.11.1
Pillow==9.5.0
pip==23.2.1
platformdirs==3.8.0
ply==3.11
pre-commit==3.3.3
projectq==0.8.0
psutil==5.9.5
pycparser==2.21
pyparsing==3.1.0
python-dateutil==2.8.2
pytz==2023.3
PyYAML==6.0
qiskit==0.43.1
qiskit-aer==0.12.0
qiskit-ibmq-provider==0.20.2
qiskit-terra==0.24.1
requests==2.31.0
requests-ntlm==1.1.0
ruff==0.0.275
rustworkx==0.13.0
scikit-learn==1.2.2
scipy==1.10.1
seaborn==0.12.2
setuptools==68.0.0
six==1.16.0
soupsieve==2.4.1
stevedore==5.1.0
symengine==0.9.2
sympy==1.12
threadpoolctl==3.1.0
types-beautifulsoup4==4.12.0.6
types-html5lib==1.1.11.15
types-Pillow==10.0.0.3
types-pytz==2023.3.1.1
types-requests==2.31.0.1
types-urllib3==1.26.25.13
typing_extensions==4.6.3
tzdata==2023.3
urllib3==2.0.3
virtualenv==20.23.1
websocket-client==1.6.1
websockets==11.0.3
wheel==0.40.0
```
</details>

### Expected behavior

The file calculates exponentiation, `a ** b`.

### Actual behavior

The file calculates multiplication, `a * b`.
```py
>>> import maths.binary_exponentiation_2 as binexp
>>> binexp.b_expo(2, 3)
6
```

This file should be renamed to `binary_multiplication.py`. Also, we need doctests in this file so that basic errors like this can be caught.

Hacktoberfest contributors: **Do not ask to work on this issue.** If you want to work on it, just open a PR. Read the contributing guidelines.


Discussion:
Hi, I created a [PR](https://github.com/TheAlgorithms/Python/pull/9504) Can you please check it.

Resolving patch:
diff --git a/maths/binary_exponentiation_2.py b/maths/binary_exponentiation_2.py
deleted file mode 100644
--- a/maths/binary_exponentiation_2.py
+++ /dev/null
@@ -1,50 +0,0 @@
-"""
-* Binary Exponentiation with Multiplication
-* This is a method to find a*b in a time complexity of O(log b)
-* This is one of the most commonly used methods of finding result of multiplication.
-* Also useful in cases where solution to (a*b)%c is required,
-* where a,b,c can be numbers over the computers calculation limits.
-* Done using iteration, can also be done using recursion
-
-* @author chinmoy159
-* @version 1.0 dated 10/08/2017
-"""
-
-
-def b_expo(a: int, b: int) -> int:
-    res = 0
-    while b > 0:
-        if b & 1:
-            res += a
-
-        a += a
-        b >>= 1
-
-    return res
-
-
-def b_expo_mod(a: int, b: int, c: int) -> int:
-    res = 0
-    while b > 0:
-        if b & 1:
-            res = ((res % c) + (a % c)) % c
-
-        a += a
-        b >>= 1
-
-    return res
-
-
-"""
-* Wondering how this method works !
-* It's pretty simple.
-* Let's say you need to calculate a ^ b
-* RULE 1 : a * b = (a+a) * (b/2) ---- example : 4 * 4 = (4+4) * (4/2) = 8 * 2
-* RULE 2 : IF b is ODD, then ---- a * b = a + (a * (b - 1)) :: where (b - 1) is even.
-* Once b is even, repeat the process to get a * b
-* Repeat the process till b = 1 OR b = 0, because a*1 = a AND a*0 = 0
-*
-* As far as the modulo is concerned,
-* the fact : (a+b) % c = ((a%c) + (b%c)) % c
-* Now apply RULE 1 OR 2, whichever is required.
-"""
diff --git a/maths/binary_multiplication.py b/maths/binary_multiplication.py
new file mode 100644
--- /dev/null
+++ b/maths/binary_multiplication.py
@@ -0,0 +1,101 @@
+"""
+Binary Multiplication
+This is a method to find a*b in a time complexity of O(log b)
+This is one of the most commonly used methods of finding result of multiplication.
+Also useful in cases where solution to (a*b)%c is required,
+where a,b,c can be numbers over the computers calculation limits.
+Done using iteration, can also be done using recursion
+
+Let's say you need to calculate a * b
+RULE 1 : a * b = (a+a) * (b/2) ---- example : 4 * 4 = (4+4) * (4/2) = 8 * 2
+RULE 2 : IF b is odd, then ---- a * b = a + (a * (b - 1)), where (b - 1) is even.
+Once b is even, repeat the process to get a * b
+Repeat the process until b = 1 or b = 0, because a*1 = a and a*0 = 0
+
+As far as the modulo is concerned,
+the fact : (a+b) % c = ((a%c) + (b%c)) % c
+Now apply RULE 1 or 2, whichever is required.
+
+@author chinmoy159
+"""
+
+
+def binary_multiply(a: int, b: int) -> int:
+    """
+    Multiply 'a' and 'b' using bitwise multiplication.
+
+    Parameters:
+    a (int): The first number.
+    b (int): The second number.
+
+    Returns:
+    int: a * b
+
+    Examples:
+    >>> binary_multiply(2, 3)
+    6
+    >>> binary_multiply(5, 0)
+    0
+    >>> binary_multiply(3, 4)
+    12
+    >>> binary_multiply(10, 5)
+    50
+    >>> binary_multiply(0, 5)
+    0
+    >>> binary_multiply(2, 1)
+    2
+    >>> binary_multiply(1, 10)
+    10
+    """
+    res = 0
+    while b > 0:
+        if b & 1:
+            res += a
+
+        a += a
+        b >>= 1
+
+    return res
+
+
+def binary_mod_multiply(a: int, b: int, modulus: int) -> int:
+    """
+    Calculate (a * b) % c using binary multiplication and modular arithmetic.
+
+    Parameters:
+    a (int): The first number.
+    b (int): The second number.
+    modulus (int): The modulus.
+
+    Returns:
+    int: (a * b) % modulus.
+
+    Examples:
+    >>> binary_mod_multiply(2, 3, 5)
+    1
+    >>> binary_mod_multiply(5, 0, 7)
+    0
+    >>> binary_mod_multiply(3, 4, 6)
+    0
+    >>> binary_mod_multiply(10, 5, 13)
+    11
+    >>> binary_mod_multiply(2, 1, 5)
+    2
+    >>> binary_mod_multiply(1, 10, 3)
+    1
+    """
+    res = 0
+    while b > 0:
+        if b & 1:
+            res = ((res % modulus) + (a % modulus)) % modulus
+
+        a += a
+        b >>= 1
+
+    return res
+
+
+if __name__ == "__main__":
+    import doctest
+
+    doctest.testmod()


Test patch: