<p>i'm just a tech newbie learning how ec cryptography works and stumbled into a problem with my python code</p>
<p>i'm testing basic elliptic curve operations like adding points, multiple by G etc, let's say i have</p>
<pre><code>Ax = 0xbc46aa75e5948daa08123b36f2080d234aac274bf62fca8f9eb0aadf829c744a
Ay = 0xe5f28c3a044b1cac54a9b4bf719f02dfae93a0bae73832301e786104f43255a5
A = (Ax,Ay)

f = open('B-coordinates.txt', 'r')
data = f.read()     
f.close()     
print (data)            
B = 'data'
</code></pre>
<p>there B-coordinates.txt contains lines like
(0xe7e6bd3424a1e92abb45846c82d570f0596850661d1c952f9fe3564567d9b9e8,0x59c9e0bba945e45f40c0aa58379a3cb6a5a2283993e90c58654af4920e37f5)</p>
<p>then i perform basic point addition A+B add(A,B)</p>
<p>so because of B = 'data' i obviously have this error</p>
<pre><code>TypeError: unsupported operand type(s) for -: 'int' and 'str'
</code></pre>
<p>and if i add int(data) &gt; <code>Error invalid literal for int() with base 10:</code> because letters in input (i.e. in points coordinates).</p>
<p>so my question is, please can someone knowledgeable in python and  elliptic curve calculations tell me how to add the coordinates of a point so as to bypass these int problems when extracting lines from a file into .py? I will be very grateful for the answer! I've been trying to figure out how to do it right for many hours now, and maybe just goofing off, but please I'll appreciate any hints</p>

CC BY-SA 4.0
2022-09-27T19:46:18.393Z
I’m voting to close this question because it is a basic Python programming question, unrelated to Bitcoin or the cryptography used in it.
Pieter Wuille
CC BY-SA 4.0
2022-09-27T20:11:30.487Z
please leave it - python stackoverflow answers have become very slow these days, maybe someone here can help me with this question. thank you!
user136859
CC BY-SA 4.0
2022-09-27T22:05:41.453Z
@user136859: You know that 0x at the start of the string represents hexadecimal right? To add hexademical together https://stackoverflow.com/questions/45640652/adding-subtracting-hexadecimals. It is point addition too of course
Michael Folkson
<python>
How to add elliptic curve points from a file?
user136859
# How to add elliptic curve points from a file?

(Asked by: username_0 on 2022-09-27)

i'm just a tech newbie learning how ec cryptography works and stumbled into a problem with my python code

i'm testing basic elliptic curve operations like adding points, multiple by G etc, let's say i have

```
Ax = 0xbc46aa75e5948daa08123b36f2080d234aac274bf62fca8f9eb0aadf829c744a
Ay = 0xe5f28c3a044b1cac54a9b4bf719f02dfae93a0bae73832301e786104f43255a5
A = (Ax,Ay)

f = open('B-coordinates.txt', 'r')
data = f.read()     
f.close()     
print (data)            
B = 'data'

```

there B-coordinates.txt contains lines like
(0xe7e6bd3424a1e92abb45846c82d570f0596850661d1c952f9fe3564567d9b9e8,0x59c9e0bba945e45f40c0aa58379a3cb6a5a2283993e90c58654af4920e37f5)

then i perform basic point addition A+B add(A,B)

so because of B = 'data' i obviously have this error

```
TypeError: unsupported operand type(s) for -: 'int' and 'str'

```

and if i add int(data) > `Error invalid literal for int() with base 10:` because letters in input (i.e. in points coordinates).

so my question is, please can someone knowledgeable in python and elliptic curve calculations tell me how to add the coordinates of a point so as to bypass these int problems when extracting lines from a file into .py? I will be very grateful for the answer! I've been trying to figure out how to do it right for many hours now, and maybe just goofing off, but please I'll appreciate any hints

**Tags:** python

> **Comments:**
> **username_1**: I’m voting to close this question because it is a basic Python programming question, unrelated to Bitcoin or the cryptography used in it.  
> **username_0**: please leave it - python stackoverflow answers have become very slow these days, maybe someone here can help me with this question. thank you!  
> **username_2**: @username_0: You know that 0x at the start of the string represents hexadecimal right? To add hexademical together https://stackoverflow.com/questions/45640652/adding-subtracting-hexadecimals. It is point addition too of course  

---

## 0 answers

