Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6597091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:09:50+00:00 2026-05-25T18:09:50+00:00

In my cryptography project, I have to deal with GF(2^8) arithmetic operations. Essentially, the

  • 0

In my cryptography project, I have to deal with GF(2^8) arithmetic operations. Essentially, the sum operation in this this field (GF(2^8) is normal XOR operation, and the product operation a*b is (a*b) mod m(x). You can skip this mathematics part.

My job is to inverse a matrix 4×4 in GF(2^8). This is not difficult, but it’s too tedious to re-implement every matrix operations by hand. I would like to make use of this functionality (inverse a matrix) in numpy, but I was not able to make numpy use my operations between items of a matrix. Say, instead of performing adding between 2 items using ‘+’, I want it to perform XOR whenever ‘+’ operation is used.

I have created a class of my customer type, call GF28. The code can be found below:

class GF28(float):
    def __init__(self, value):
        self.value = value
    def __add__(self, b):        
        if isinstance(b, GF28):
            return GF28(ops.add(self.value, b.value))
        else:
            return GF28(ops.add(self.value, b))
    __rsub__ = __isub__ = __sub__ = __radd__ = __iadd__ = __add__

    def __mul__(self, b):
        if isinstance(b, GF28):
            return GF28(ops.mul(self.value, b.value))
        else:
            return GF28(ops.mul(self.value, b))
    __rmul__ = __imul__ = __mul__

    def __div__(self, b):
        return self.__mul__(self.inv(b))
    __rdiv__ = __idiv__ = __div__

    def inv(self):
        return GF28(ops.inv(self.value))
    def __float__(self):        
        return self

And then I create a matrix of these GF28 items using:

a = array([[GF28(10), GF28(20), GF28(30)],
           [GF28(12), GF28(21), GF28(4)],
           [GF28(9), GF28(16), GF28(13)]])

It appears that only the float() cast function is being used, the rest is not touched at all.

Please help me to make this operation overriding work. Thanks a lot.

[edit] Performing basic matrix operation is already ok. If somebody could make this work with matrix inversion, I would really appreciate it. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T18:09:51+00:00Added an answer on May 25, 2026 at 6:09 pm

    Declare a to be of dtype object:

    a = np.array([(GF28(10), GF28(20), GF28(30)),
                  (GF28(12), GF28(21), GF28(4)),
                  (GF28(9), GF28(16), GF28(13))],dtype='object')
    

    Then the type of the elements in the array are GF28. For example:

    type(a[0,0])
    # <class '__main__.GF28'>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Working on a project, I have this issue where my array slicetable returns undefined
I have C++ CLR project with both managed and unmanaged code. In this project
I have a WPF application (KaleidoscopeApplication) organized as follows: Solution (6 projects) Cryptography (DLL)
This is more of a cryptography theory question, but is it possible that the
I want to use the cryptography in the Portable Class Library Contrib project on
I have a class in my C# project marked with the [Serializable] attribute. It
I just finished a project for my cryptography class and it all seems to
currently im using System.Security.Cryptography and this is my code for it: private static SymmetricAlgorithm
I want to use an asymmetric cryptography algorithm, but I need it have short
I have created a project in NetBeans by downloading some third party jars of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.