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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T08:50:48+00:00 2026-05-30T08:50:48+00:00

Is there an existing function to generate the server response key in Lua? Here

  • 0

Is there an existing function to generate the server response key in Lua? Here is the solution in python: websocket handshake problem

I do have the two key numbers captured, the spaces counted, the third string captured and hoping the rest lies in an existing function…

  • 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-30T08:50:50+00:00Added an answer on May 30, 2026 at 8:50 am

    If need the older handshake (protocol 0), you can use the following code to get the handshake value from the two keys:

    md5 = require 'md5'
    
    function getnumbers(str)
        local num = ""
        str:gsub('%d', function(d) num = num .. d end)
        return tonumber(num)
    end
    function countspaces(str)
        return select(2, str:gsub(' ', ' '))
    end
    function to32bitint(i)
        return string.char(i/256^3 % 256, i/256^2 % 256, i/256 % 256, i % 256)
    end
    function websocketresponse(key1, key2, end8)
        local n1, s1 = getnumbers(key1), countspaces(key1)
        local n2, s2 = getnumbers(key2), countspaces(key2)
        local cat = to32bitint(n1/s1) .. to32bitint(n2/s2) .. ending8
        return md5.sum(cat)
    end
    
    websocket_key1 = "18x 6]8vM;54 *(5:  {   U1]8  z [  8"
    websocket_key2 = "1_ tx7X d  <  nw  334J702) 7]o}` 0"
    ending8 = "Tm[K T2u"
    print(websocketresponse(websocket_key1, websocket_key2, ending8))
    --> fQJ,fN/4F4!~K~MH
    

    This produces the same value as the example given in the protocol draft. This example uses MD5 library to calculate the checksum and is available compiled in LuaForWindows.

    The implementation for WebSocket protocol version 6 is much simpler:

    crypto = require 'crypto'
    mime = require 'mime'
    
    function websocketresponse6(key)
        local magic = key .. "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
        return (mime.b64(crypto.digest('sha1', magic, true)))
    end 
    
    key6 = "x3JJHMbDL1EzLkh9GBhXDw=="
    print(websocketresponse6(key6))
    --> HSmrc0sMlYUkAGmm5OPpG2HaGWk=
    

    This example uses the LuaCrypto for SHA1 sum and MIME from LuaSocket.

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

Sidebar

Related Questions

Is there an existing function to replace accented characters with unadorned characters in PostgreSQL?
There's an existing function that ends in the following, where d is a dictionary:
Are there existing template extract libraries in either python or php? Perl has Template::Extract
Is there an existing solution to create a regular expressions dynamically out of a
Are there any existing solutions for remote execution of commands on a windows server
Is there existing software for discriminative reranking, such as that used by the Charniak
Is there an existing application or library in Java which will allow me to
Is there any existing code in Apache HttpClient or in the servlet API to
Is there an existing PL/SQL method which takes a string and returns the same
Are there any existing libraries in existence that will parse a datetime from a

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.