Why isnt my equation evalutaing correctly?
So I'm making a BCH decoder for a uni project in Python. It takes a 10 digit codeword with or without errors and is supposed to detect and correct any errors it finds. For double error correction there is a mathmatical formula to detect the position and magnitute of these errors:
formula for error pos and mag
i = (Q + ((Q^24*P*R)^(1/2))/2*P)<br/>
j = (Q  ((Q^24*P*R)^(1/2))/2*P)
b = (i*s1s2)/(ij)<br/>
a = s1b
I have already correctly calculated QPR and s1,s2.
So, I'm debugging with this example (2 error BCH example). It has the number 8888880747
being transmitted to 8899880747
so there are 2
errors in positions 3 and 4 both by a magnitute of 1. So far my program generates the correct syndromes(s1 to s4  2,7,3,3)
and the correct PQR values (10,7,10)
but when doing the calculation for i and j I get different values than the example  10.7
and 10.6
as opposed to 3
and 4
.
Here is my code for i and j:
#work out error positions i and j
sqrt = ((Q**2  4*P*R) % 11)**(1/2)
i = (((Q+sqrt)/(2*P))%11)
j = (((Qsqrt)/(2*P))%11)
Can anyone see what I'm doing wrong? Thanks.
1 answer

The operations are meant to be carried in
GF(11)
, in other words they are meant to be carried out mod 11. Square roots and division mod 11 are different than they are in the real numbers.There are advanced algorithms for doing both square roots and modular inverses but for numbers as small as 11 you can just use brute force or precompute a table. Go with first principles here. For sqrt(x) try [0,1,2,...10] and see which one when squared is equal to x. That is the square root. For division (inverses), 1/x, try [0,1,2,...10] and see which one when multiplied by x is equal to 1 mod 11. Now we plugin these value to get i = 3, j = 4.
So, going through the calculations mod 11, we have:
P, Q, R = (10,7,10) (Q**2  4*P*R) = 351, 351 % 11 = 1 That's convenient since the square root of 1 is just 1 mod 11. Looking at the next two equations we see we are going to need to compute 1/(2*P) mod 11, in other words we need to find the inverse of 2*P mod 11, i.e. (2P)^{1} mod 11. 2*P % 11 = 20 % 11 = 9. By trying all the possibilities we find that 9^{1} mod 11 is 5.
See also questions close to this topic

How can I get data from 'ravi' file?
What
ravi
file is:A RAVI file is a video file created by thermal imaging software, such as MicroEpsilon TIM Connect or Optris PIX Connect. It contains video captured by thermal cameras and is saved in a format similar to the Audio Video Interleave (.AVI) format. RAVI files also store radiometric information, such as temperature and measurement area information collected by the thermal camera.
My issue:
I have to work with data from the
ravi
file. I need the temperature value for the pixels (Or the maximum temperature of the frame is enough for me). I would like to check the maximum temperature on a certain frame. The final result would be a report which contains the maximum temperature values on frames (It would be a graph). It is easy to check and process withMicroEpsilon TIM Connect
orOptris PIX Connect
tools but I am not able to use them (I have to write an own one).My questions:
 How can I get the data from
ravi
file?  Is there any converter to convert
ravi
file to another?
Note:
 The Python language is the preferred but I am open for every idea.
 I have to work with the
ravi
files and I am not able to record new files or modify the recording.  I have found a site which provides a
SDK
for this type of camera but it is not clear for me that get data fromravi
file is possible. Link tolibirimager2
documentation: libirimager2
Edit:
If I parse it with OpenCV, I can show the image. But I am not sure how I can get the temperature...
CV2 code:
import cv2 cap = cv2.VideoCapture("my_test.ravi") if not cap.isOpened(): print("Error opening video stream or file") while cap.isOpened(): ret, frame = cap.read() if ret: cv2.imshow('Frame', frame) if cv2.waitKey(25) & 0xFF == ord('q'): break cap.release() cv2.destroyAllWindows()
Shown video:
ravi
file in HexEditor:I have found a site about AVI video format. You can see below some lines from begging of my file, perhaps it can help.
00000000 52 49 46 46 F8 B1 C6 3F 41 56 49 20 4C 49 53 54 RIFF...?AVI LIST 00000010 CC 7F 00 00 68 64 72 6C 61 76 69 68 38 00 00 00 ....hdrlavih8... 00000020 12 7A 00 00 44 FF DD 00 00 02 00 00 10 08 00 00 .z..D........... 00000030 44 6D 00 00 00 00 00 00 01 00 00 00 08 65 09 00 Dm...........e.. 00000040 80 02 00 00 E1 01 00 00 00 00 00 00 00 00 00 00 ................ 00000050 00 00 00 00 00 00 00 00 4C 49 53 54 74 7E 00 00 ........LISTt~.. 00000060 73 74 72 6C 73 74 72 68 38 00 00 00 76 69 64 73 strlstrh8...vids 00000070 59 55 59 32 00 00 00 00 00 00 00 00 00 00 00 00 YUY2............ 00000080 B4 C4 04 00 80 96 98 00 00 00 00 00 A4 50 00 00 .............P.. 00000090 08 65 09 00 00 00 00 00 00 00 00 00 00 00 00 00 .e.............. 000000A0 00 00 00 00 73 74 72 66 28 00 00 00 28 00 00 00 ....strf(...(... 000000B0 80 02 00 00 E1 01 00 00 01 00 10 00 59 55 59 32 ............YUY2 000000C0 00 65 09 00 60 00 00 00 60 00 00 00 00 00 00 00 .e..`...`....... 000000D0 00 00 00 00 69 6E 64 78 F8 7D 00 00 04 00 00 00 ....indx.}...... 000000E0 06 00 00 00 30 30 64 62 00 00 00 00 00 00 00 00 ....00db........
 How can I get the data from

Google cloud Speech Recognition library
i am using Google cloud Speech Recognition library to convert my voice into text. it is working correctly but when it didn't listen to something for some time it through the following error.
Traceback (most recent call last): File "<ipythoninput5c879bb27fe9b>", line 1, in <module> runfile('C:/Users/MrWD/Desktop/Soeech Recognition.py', wdir='C:/Users/MrWD/Desktop') File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\sitepackages\spyder_kernels\customize\spydercustomize.py", line 827, in runfile execfile(filename, namespace) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\sitepackages\spyder_kernels\customize\spydercustomize.py", line 110, in execfile exec(compile(f.read(), filename, 'exec'), namespace) File "C:/Users/MrWD/Desktop/Soeech Recognition.py", line 20, in <module> text = r.recognize_google(audio, language = 'urPK') File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\sitepackages\speech_recognition\__init__.py", line 840, in recognize_google response = urlopen(request, timeout=self.operation_timeout) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\urllib\request.py", line 222, in urlopen return opener.open(url, data, timeout) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\urllib\request.py", line 525, in open response = self._open(req, data) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\urllib\request.py", line 543, in _open '_open', req) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\urllib\request.py", line 503, in _call_chain result = func(*args) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\urllib\request.py", line 1345, in http_open return self.do_open(http.client.HTTPConnection, req) File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\urllib\request.py", line 1320, in do_open r = h.getresponse() File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\http\client.py", line 1321, in getresponse response.begin() File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\http\client.py", line 296, in begin version, status, reason = self._read_status() File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\http\client.py", line 257, in _read_status line = str(self.fp.readline(_MAXLINE + 1), "iso88591") File "C:\Users\MrWD\AppData\Local\Programs\Python\Anaconda\lib\socket.py", line 589, in readinto return self._sock.recv_into(b) KeyboardInterrupt
can anyone give me its solution...

How to cancel event in a function
I need to cancel a specific event in which the user input the name. However
s.cancel
never allows me to do that since I'm guessing the variable is local. What can I do?Here is my code:
import sched import time s = sched.scheduler(time.time, time.sleep) def print_job_name(msg): print(msg) def alarm(name): name = s.enter(5,1,print_job_name,("Hey",)) print(type(name)) return name alarm('hey') alarm('Good Morning') alarm('hello') s.cancel(hey) s.run()

Extract Rotation and Scale from 3x3 Matrix
I work on a tool to convert old 3d data from a program and convert it into a new format. The problem i have is, the old program is storring the scale/rotation in a 3x3 matrix and i have no experiance with this kind of stuff.
For testing i have created an object only with scale 0.5 and saved it. It has the matrix
0.5, 0.0, 0.0
0.0, 0.5, 0.0
0.0, 0.0, 0.5
These are the scales for all 3 axis
Then i changed the object to have only rotations xyz of 45 degrees and a scale of 1 and got this matrix
0.5, 0.146447, 0.853553
0.5, 0.853553, 0.146447
0.707107, 0.5, 0.5
I was able to convert this to the correct angles
Now i come to my showstopper: i changed the object to have a scale of 0.5 and a rotation of 45 degrees. The new matrix somehow combined both values into one matrix:
0.25, 0.0732233, 0.426777
0.25, 0.426777, 0.0732233
0.353553, 0.25, 0.25
Basically the vales are the half of the secound matrix. Currently im not able to figure out how to get the scale and the rotation out of this matrix, basically seperate them from each other. So if someone has an idea how this has to be done it world be great.

JS: Return a number to a specified power of 10
I'm working on a problem that requires me to return a number rounded to a specified power of 10. For example:
1234, specified power = 2 => 1200 1234, specified power = 3 => 1000
I did find a solution to the problem with this function:
const roundToPower = (num, pow) => { return Math.round(num / Math.pow(10, pow)) * Math.pow(10,pow) };
However, I am not exactly sure how and why it works.
Is someone able to break it down for me? Thanks!

What is a mathematical model?
I came across ADT (Abstract Data Type), so I decided to learn.
In computer science, an abstract data type (ADT) is a mathematical model for data types, where a data type is defined by its behavior (semantics) from the point of view of a user of the data, specifically in terms of possible values, possible operations on data of this type, and the behavior of these operations.
~https://en.wikipedia.org/wiki/Abstract_data_type
"a mathematical model for data types" ??
I've been searching endlessly, trying to develop a feel for what a "mathematical model" is, apparently, it's just a "description of a system using mathematical concepts and language". Still not clear.
There aren't many if not any StackOverflow questions about this and I've run out of places to find a good explanation, so I had to ask.

What happens when Shor's algorithm meets a byte string that wasn't encrypted with AES?
I believe I have created an uncrackable encryption. First the plaintext is encrypted with an AES script that I randomly found on the net. The resulting byte string is chopped up using a onetime pad (OTP), and the OTP uses seeds to pseudorandomly generate keys and a character list. The keys are 09 and the character list consists of letters, numbers and special characters. I posit that if you were to use a quantum computer to decrypt this message you would return multitudes of false positives, rendering the whole process pointless.
Let us start simple. Say the character list of the OTP is:
character_list = """abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890."‘'’—():;!@/#$%^&=_+/\,?<>`~ """
... and the crypted message is:
msg_in = "46 10 11 100 20 29 12 9 16 100 8 18 23 24 18 100 7 14 24 100 16 26 13 19 27 99 16 29 10 18 96 19 16 6 103 17 4 25 33 97 4 22 15"
As long as you have the original list, your ordinary laptop can crack the message within an hour by brute forcing the keys and searching for common words:
common_words = ['the','and','that','for','you','was','what','into','day','get','quick','brown','fox','jumps','over','lazy','dog']
Now consider a brute force script that introduces a point system where for each English character it finds it adds a point. After running our script we have the following:
seed: 6  points: 1  message: yYkMV0o=!k.@wOXox40?%)vTMBDtheMPlzFJ? PT5,R6`F*/
seed: 248  points: 1  message: yhLWcz?xz!5@aOfoxt(yp/nsERrCY6f7zFWR?`.—)KOB/Hfj
seed: 1234  points: 11  message: The quick brown fox jumps over the lazy dog. for and that
seed: 1602  points: 1  message: 8H(EcL/q>Uu5s@nXT>gbTXo /Z'HCId%fz.’‘?3iUfoQt9Othat
seed: 1674  points: 1  message: yI#M;>su(br?@Z%wuC0ysT’@veH:6 aluQW'PU.p)Qand/S
seed: 179335  points: 2  message: yYL ^>/z>by8P~Ufox4LXsUTWJKUg&RU%a;. dogDP85,v#gFa4
For each common word found in the output it is given 1 point. A higher score means that you have a better match. As long as you begin with the original character list of AZ, 09 etc, you can crack the message within minutes. The possibility of finding the exact message is:
one in : the number of characters in the character list to the power of 10.
Now for the advanced OTP. You can use a seed to shuffle the character list and make it more secure. This makes the equation:
one in : the number of characters in the character list to the power of the number of characters in the character list.
(insert info on the strength of the seed length)
Enough for the introduction. My encryption begins with AES and is then converted into integers using an advanced OTP. Take a byte string like:
b'\xcf\x84o\xcf\x81\xce\xbdo\xcf\x82'
Each character would be converted into a number. Any person that stumbles upon the encrypted message would see a series of numbers between 1105 (the number of characters in our character list. Assuming you knew that it was using this exact encryption method and working backwards, you would need to arbitrarily create every possible combination of byte string's and then decrypt them using shor's algorithm.
The question is, what happens when Shor's algorithm meets a byte string that wasn't encrypted with AES?

Sign PDF file with java and PDFBox
I'm trying to sign a PDF file. I have function for digital signature, which I want to use. It's an implementation of ECDSA using SHA256, it takes byte array of data to be signed and returns byte array with signature and public key. I have this code, but I don't know, how to implement the sign function using the function I already have.
import java.io.IOException; import java.io.InputStream; import java.util.Calendar; import org.apache.pdfbox.pdmodel.PDDocument; import org.apache.pdfbox.pdmodel.PDPage; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.PDSignature; import org.apache.pdfbox.pdmodel.interactive.digitalsignature.SignatureInterface; public class main { public static void main(String[] args) { PDDocument pdDocument = new PDDocument(); PDPage pdPage = new PDPage(); pdDocument.addPage(pdPage); try { PDSignature pdSignature = new PDSignature(); pdSignature.setFilter(PDSignature.FILTER_VERISIGN_PPKVS); pdSignature.setSubFilter(PDSignature.SUBFILTER_ADBE_PKCS7_SHA1); pdSignature.setName("Name"); pdSignature.setLocation("location"); pdSignature.setReason("test"); pdSignature.setSignDate(Calendar.getInstance()); pdDocument.addSignature(pdSignature, new SignatureInterface() { public byte[] sign(InputStream inputStream) throws IOException { return new byte[0]; } }); pdDocument.save("test"); pdDocument.close(); System.out.println("PDF saved to the location !!!"); } catch (IOException ioe) { System.out.println("Error while saving pdf" + ioe.getMessage()); } } }

Pedersen commitments not behaving as expected using elliptic library
I am implementing Pedersen commitments in Javascript using elliptic library and am facing some issues. I am not quite sure if they originate from my implementation or from BigInt to bn.js conversion, modulos issues or some other incompatibilities.
Here is how I define my Pedersen commitments:
/** * Generate a Pedersen commitment * on secp256k1 curve * * @param v {BigInt} The value we want to commit to * @param x {BigInt} The blinding factor * @param H {Point} Second generator point used in the commitment */ static getPedersenCommitment(v, x, H=null) { if( H === null ) { H = Utils.getHFromHashingG(ec.g); } const G = ec.g; const x_BN = Utils.toBN(x); const v_BN = Utils.toBN(v); return G.mul(v_BN).add(H.mul(x_BN)) }
Here is my conversion from BigInt to bn.js
/** * Convert BigInt to BN (used in elliptic) * * @param bgint {BigInt} * @return {BN} */ static toBN(bgint) { return new BN(bgint.toString(16), 'hex'); }
Now since the % operator in Javascript might give me negative numbers I am using my own modulos function:
/** * Modulos funtion always returning the * positive modulos not the remainder * * @param num {BigInt} initial number * @param n {BigInt} the mod number * @return {BigInt} */ static mod(num, n) { return ((num % n) + n) % n; }
I have written two tests specifically related to negative numbers, this one here is passing:
it('Test mult properties of pedersen with negative num 1', () => { const p = secp256k1.p; const t1 = Maths.mod(4424687248756834944667496427199067151987779098219282389160949909025658367322n, p); const x = Maths.mod(38659561957554344830346811456777626115164894886626759056962864666140509109118n, p); const xBN = Utils.toBN(x); const r = Maths.mod(206032474729127474062261152183333172264689698899312462254655119185748812599n, p); const T1 = Utils.getPedersenCommitment(t1, r); const T1cmp = Utils.getPedersenCommitment(t1 * x, r * x); assert(T1.mul(xBN).eq(T1cmp)); });
This one here is very similar but failing:
it('Test mult properties of pedersen with negative num 2', () => { const p = secp256k1.p; const t1 = Maths.mod(4424687248756834944667496427199067151987779098219282389160949909025658367322n, p); const x = Maths.mod(38659561957554344830346811456777626115164894886626759056962864666140509109118n, p); const xBN = Utils.toBN(x); const r = Maths.mod(206032474729127474062261152183333172264689698899312462254655119185748812599n, p); const T1 = Utils.getPedersenCommitment(t1, r); const T1cmp = Utils.getPedersenCommitment(Maths.mod(t1 * x, p), Maths.mod(r * x, p)); assert(T1.mul(xBN).eq(T1cmp)); });
I do not understand why the second test is failing. Since every point on the curve should be mod p anyhow.

Smallest integer with 21 divisors
Not sure I understand this explanation.
I'm assume you want exactly 21 divisors.
Let's say you have a prime factorization of a number: (p₁^n₁) × (p₂^n₂) × (p₃^n₃) × ...
Then the number of divisor can be found by adding one to each exponent and multiplying them together: (n₁+1) × (n₂+1) × (n₃+1) × ...
In your case, you want 21 factors. Figuring out which numbers multiply to be 21, we have: 1 × 21 or 3 × 7
The corresponding exponents would then be: 0, 20 or 2, 6
It's pretty obvious that raising something to the 20th power will result in a really big number, so that won't be the solution. The two smallest primes are 2 and 3, so we have two possible numbers to try: 2² × 3⁶ = 2916 or 2⁶ x 3² = 576
The smallest positive integer is therefore 576.
Just to be thorough, here are the 21 integer factors of 576: 1, 2, 3, 4, 6, 8, 9, 12, 16, 18, 24, 32, 36, 48, 64, 72, 96, 144, 192, 288, 576

Find the smallest value of the following expression $sqrt((x9)^2 +4) + sqrt(x^2+y^2) + sqrt((y3)^2 +9)$
Find the smallest value of the following expression:
$sqrt((x9)^2 +4) + sqrt(x^2+y^2) + sqrt((y3)^2 +9)$
I tried to derive the expression with respect to x and y and then equal the derivative to zero and find the critical points, but I could not do that. it is complicated. is there a way?

what is the greatest possible number of units in an invertable binary 10 x 10 matrix?
the question: the matrix with all entries either 0 or 1 is called a binary matrix. what is the greatest possible number of units in an invertible binary 10 x 10 matrix?
my approach is that we have
2^10 = 1024
different matrices that can be obtained. we will now subtract the matrices that are not invertible.first the zero matrix
( 1024  1 = 1023)
the matrices that have a full single column of zeros( 1023  10 = 1013)
the matrices that have a full single row of zeros( 1013  10 = 1003)
but now I need to consider all combinations of rows and columns of zeros.
is my approach correct? and how I can get the answer.
the correct answer is 91 matrices.