Finding matrix modular for encryption

조회 수: 7 (최근 30일)
Fatma Alnabrisi
Fatma Alnabrisi 2019년 12월 3일
댓글: Fatma Alnabrisi 2019년 12월 4일
Can someone please help me in writing a function which takes any matrix A as an input, and finds (A mod 29).
Considering that elements of A are real numbers and the outputs have to be integers.
For example (1/2 mod 29 = 15) .. (-3/2 mod 29 = 13) in https://planetcalc.com/8326/
I need this function for just a small part in my college project and actually I don't understand the math behind it.
Thank you

채택된 답변

Walter Roberson
Walter Roberson 2019년 12월 3일
You will have problems with this due to the limited precision available to real numbers. For example, 1/3 and 1/10 cannot be exactly represented in binary floating point arithmetic.
A first step would be converting the floating point number into a rational, but doing that is risky. How, for example, do you know for sure that 0.52941176470588235947190014485386200249195098876953125 is intended as 9/17 and not as 4768517252509937/9007199254740992 ?
My recommendation would be not to do what you are trying to do. You would be better off using a pair of rationals, such as [-3, 2] or [9, 17] instead of -1.5 and 0.52941176470588235947190014485386200249195098876953125
  댓글 수: 1
Fatma Alnabrisi
Fatma Alnabrisi 2019년 12월 4일
My matrix A actually goes through several calculations before I need to find (A mod 29)
so, how can I force the elements of A to be rational numbers instead?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by