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 7170757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:16:35+00:00 2026-05-28T15:16:35+00:00

How to take integer in hashlib.sha1(int). Please see the code in which i am

  • 0

How to take integer in hashlib.sha1(int).
Please see the code in which i am taking IP as string converting it as integer now at hash.sha1 doest take integer…

 import hashlib
 import socket
 import struct
  class blommy(object):
   def __init__(self):
    self.bitarray= [0]*2048

  def hashes(self,ip):
    #convert decimal dotted quad string to long integer"
    intip= struct.unpack('>L',socket.inet_aton(ip))[0]
    index = [0, 1]
    hbyte = hashlib.sha1(intip) # how to take sha1 of integer??
    index[0] = ord(hbyte[0])| ord(hbyte[1])<< 8
    index[1] = ord(hbyte[2])| ord(hbyte[3])<< 8

Need to convert this C code to python. Please advice some part of code is written above. If i take ip as int I cannot compute sha1 + even if convert ip using socket than sha1 dont accept it suggestion? see comments below

//fixed parameters
k = 2

m = 256*8

  //the filter
  byte[m/8] bloom   ## 

 function insertIP(byte[] ip) {

byte[20] hash = sha1(ip)

int index1 = hash[0] | hash[1] << 8 # how to in python?
int index2 = hash[2] | hash[3] << 8

// truncate index to m (11 bits required)
index1 %= m  ## ?
index2 %= m  ## ?

// set bits at index1 and index2
bloom[index1 / 8] |= 0x01 << index1 % 8   ## ??
bloom[index2 / 8] |= 0x01 << index2 % 8   ## ??
}

 // insert IP 192.168.1.1 into the filter:
    insertIP(byte[4] {192,168,1,1})
  • 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-28T15:16:37+00:00Added an answer on May 28, 2026 at 3:16 pm

    The answer to your question is no, you can calculate the hash of strings but not integers. Try something like:

    hashlib.sha1(str(1234)).digest()
    

    to get the hash of your integer as a string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What i want is to take an integer represented as a string, for example
can i get validation on weight which can take decimal values and also integer.
Take the following code: Sub Main() Dim i As Integer Dim b As Boolean
I'm looking to take an object that contains String and Integer context and that
We have a queue which contains only a single integer say a. Now this
I have a private method which take a list of integer value returns me
I have such code example val request: Defered[Int] = client.getSomeIntAsynFromSocket(); request.addCallBack(result => result.success[String]) request.addErrback(error
I have a class that currently has several methods that take integer parameters. These
I want to take multiple integer inputs in same line eg :- input -1
I want to define a method that take an integer as input and creates

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.