Skip to content

qsort is not equivalent to the original sorting algorithm #1

Closed

Description

@clowwindy

I find a bug when I try to port your code to iOS. qsort is not equivalent to the original code. It's not a stable sorting algorithm, so it will generate a different cipher with the one generated by Python or node.js server.

You can find the right implementation with bubble sort here:

https://github.com/clowwindy/shadowsocks-libev/blob/master/encrypt.c

If you want to speed up the calculation, use merge sort, which is a stable sorting algorithm with n*log(n) complexity.

Activity

  1. madeye commented on Dec 27, 2012

    @madeye
    Contributor

    Got it, I will try to implement a merge sort instead.

    By the way, current android client is a porting of shadowsocks-go with cross compiled binary using cgo. I am still working on the libev implementation and the related codes should be buggy.

    Thanks,
    Max

  2. added a commit that references this issue on Mar 24, 2018
  3. added a commit that references this issue on Aug 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions